Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define F first
- #define S second
- #define PB push_back
- #define MP make_pair
- using namespace std;
- typedef vector<int> vi;
- typedef long long ll;
- typedef pair<int,int> pi;
- string s1 = "", s2 = "";
- string pd(int posL, int posR){
- if(posL >= s1.size() || posR >= s2.size()) return "";
- string a = pd(posL+1, posR);
- string b = "";
- int newPosR = -1;
- for(int i = posR; i < s2.size(); i++){
- if(s1[posL] == s2[i]){
- newPosR = i;
- break;
- }
- }
- if(newPosR >= posR){
- b = s1[posL] + pd(posL+1, newPosR+1);
- }
- //cout << a << " " << b << endl;
- return (a.size() > b.size()) ? a : b;
- }
- void solve(){
- cin >> s1 >> s2;
- if(s1.size() > s2.size()){
- string t = s1;
- s1 = s2;
- s2 = t;
- }
- cout << pd(0, 0) << endl;
- }
- int main(){
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement