fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. string t[101][101];
  5.  
  6. string SCS(string a, string b,int n , int m){
  7. for(int i=0 ; i<n+1 ; i++){
  8. for(int j=0 ; j<m+1 ; j++){
  9. if(i==0||j==0){
  10. t[i][j]=" ";
  11. }
  12. if(a[i-1]==b[j-1]){
  13. t[i][j] = t[i-1][j-1]+(a[i-1]);
  14. }else{
  15. if(a[i-1]<b[j-1]){
  16. t[i][j] = t[i-1][j]+a[i-1];
  17. }else{
  18. t[i][j] = t[i][j]+b[j-1];
  19. }
  20. }
  21. }
  22. }
  23. return t[n][m];
  24. }
  25.  
  26. int main() {
  27. string a;
  28. string b;
  29. cin>>a;
  30. cin>>b;
  31. int n = a.length();
  32. int m = b.length();
  33. cout<<SCS(a,b,n,m);
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5424KB
stdin
geek
eke
stdout
e