Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 200;
- string strA, strB;
- int dp[N + 1][N + 1];
- int main(){
- cin >> strA >> strB;
- int mx = 0;
- int idx = 0;
- for(int i = 1; i <= strA.size(); ++i){
- for(int j = 1; j <= strB.size(); ++j){
- if(strA[i - 1] == strB[j - 1]){
- dp[i][j] = 1 + dp[i - 1][j - 1];
- }
- if(dp[i][j] > mx){
- mx = dp[i][j];
- idx = i;
- }
- }
- }
- cout << strA.substr(idx - mx, mx);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement