Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define F first
  3. #define S second
  4. #define PB push_back
  5. #define MP make_pair
  6.  
  7. using namespace std;
  8.  
  9. typedef vector<int> vi;
  10. typedef long long ll;
  11. typedef pair<int,int> pi;
  12.  
  13. string s1 = "", s2 = "";
  14.  
  15. string pd(int posL, int posR){
  16.     if(posL >= s1.size() || posR >= s2.size()) return "";
  17.  
  18.     string a = pd(posL+1, posR);
  19.     string b = "";
  20.  
  21.     int newPosR = -1;
  22.     for(int i = posR; i < s2.size(); i++){
  23.         if(s1[posL] == s2[i]){
  24.             newPosR = i;
  25.             break;
  26.         }
  27.     }
  28.     if(newPosR >= posR){
  29.         b = s1[posL] + pd(posL+1, newPosR+1);
  30.     }
  31.     //cout << a << " " << b << endl;
  32.     return (a.size() > b.size()) ? a : b;
  33. }
  34.  
  35. void solve(){
  36.     cin >> s1 >> s2;
  37.     if(s1.size() > s2.size()){
  38.         string t = s1;
  39.         s1 = s2;
  40.         s2 = t;
  41.     }
  42.     cout << pd(0, 0) << endl;
  43. }
  44.  
  45. int main(){
  46.     solve();
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement