Advertisement
Zinak

Untitled

Jul 23rd, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n,i,mx,j;
  6.     string s,p;
  7.     cin>>s>>p;
  8.     int cnt[p.size()+5][s.size()+5];
  9.     for(i=0;i<p.size();i++)
  10.     {
  11.         for(j=0;j<s.size();j++)
  12.         {
  13.             if(i==0||j==0)
  14.                 cnt[i][j]=0;
  15.             else if(p[i-1]==s[j-1])
  16.                 cnt[i][j]=cnt[i-1][j-1]+1;
  17.             else
  18.                 cnt[i][j]=max(cnt[i-1][j],cnt[i][j-1]);
  19.         }
  20.     }
  21.     cout<<cnt[p.size()][s.size()]<<endl;
  22.  
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement