Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LTTS - tìm xâu con chung dài nhất
- #include <iostream>
- #include <string>
- using namespace std;
- string x;
- string y;
- int a[100][100] = {0};
- int main()
- {
- cout<<"Nhap chuoi 1:\n";
- cin>>x;
- cout<<"Nhap chuoi 2:\n";
- cin>>y;
- int max=0;
- for(int i=1; i<x.size()+1; i++)
- {
- for(int j=1; j<y.size()+1; j++)
- {
- if(x[i-1]==y[j-1])
- {
- a[i][j]=a[i-1][j-1]+1;
- if(max<a[i][j])
- {
- max = a[i][j];
- }
- }
- else
- a[i][j]=0;
- }
- }
- cout<<max<<endl;
- for(int i=1; i<x.size()+1; i++)
- {
- for(int j=1; j<y.size()+1; j++)
- {
- if(a[i][j]==max)
- {
- for(int k=i-max; k<i; k++)
- {
- cout<<x[k];
- }
- cout<<endl;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement