Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- int i, j, dolz, dist;
- string zbor, word;
- cin >> zbor >> word;
- dolz = zbor.length();
- dist = word.length();
- int mat[dolz+1][dist+1];
- for(i=0; i<=dolz; i++)
- for(j=0; j<=dist; j++)
- mat[i][j] = 0;
- for(i=0; i<dolz; i++)
- for(j=0; j<dist; j++)
- {
- if(zbor[i]==word[j])
- mat[i+1][j+1] = mat[i][j]+1;
- else
- mat[i+1][j+1] = max(mat[i+1][j], mat[i][j+1]);
- }
- /*for(i=0; i<=dolz; i++){
- for(j=0; j<=dist; j++)
- cout << mat[i][j] << " ";
- if(j==dist) cout << endl;
- }*/
- cout << mat[dolz][dist];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment