Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define FOR(i,a,b) for(auto i=a; i!=b+1-2*(a>b); i+=1-2*(a>b))
- #define REP(i,a,b) for(auto i=a-(a>b); i!=b-(a>b); i+=1-2*(a>b))
- #define ALL(v) v.begin(),v.end()
- #define what_is(x) cout<<#x<<" is "<<x<<endl;
- #define min3(a,b,c) min(min(a,b),c)
- #define max3(a,b,c) max(max(a,b),c)
- #define SIZE 257
- #define MAXN 1000000007
- #define PI 3.141592653589793
- #define open_read1 freopen("C:\\Users\\Hepic\\Desktop\\a.txt","r",stdin)
- #define open_write1 freopen("C:\\Users\\Hepic\\Desktop\\b.txt","w",stdout)
- #define open_read freopen("rblock.in","r",stdin)
- #define open_write freopen("rblock.out","w",stdout)
- using namespace std;
- typedef long long LL;
- typedef pair<int,int> PII;
- int main()
- {
- //open_read1;
- string a,b,virus;
- cin>>a>>b>>virus;
- int n=a.length(),m=b.length();
- int dp[n+1][m+1],sub[n+1][m+1];
- for(int i=0; i<=n; i++)
- fill(dp[i],dp[i]+m+1,0);
- for(int i=0; i<=n; i++)
- fill(sub[i],sub[i]+m+1,0);
- for(int i=1; i<=n; i++)
- {
- for(int j=1; j<=m; j++)
- {
- //cout<<a[i-1]<<" "<<b[j-1]<<endl;
- if(a[i-1]==b[j-1])
- dp[i][j]=dp[i-1][j-1]+1,sub[i][j]=2;
- else
- dp[i][j]=max(dp[i-1][j],dp[i][j-1]),sub[i][j]=1;
- //cout<<dp[i][j]<<" ";
- }
- //cout<<endl;
- }
- string str;
- int i=n,j=m,o=0;
- while(1)
- {
- if(sub[i][j]==2)
- {
- //cout<<a[i-1]<<endl;
- str.push_back(a[i-1]);
- i--;
- j--;
- sub[i][j]=1;
- }
- else if(sub[i][j]==1)
- {
- if(dp[i-1][j]==dp[i][j])
- i--;
- else if(dp[i][j-1]==dp[i][j])
- j--;
- }
- else if(sub[i][j]==0)
- break;
- }
- //cout<<dp[n][m]<<endl;
- string ans;
- for(int i=str.length()-1; i>=0; i--)
- ans.push_back(str[i]);
- while(1)
- {
- int temp,pos;
- for(int i=0;i<ans.length();i++)
- {
- temp=0;
- for(int j=0;j<virus.length();j++)
- {
- if((i+j)<ans.length())
- {
- if(virus[j]==ans[i+j])
- temp++;
- if(temp==1)
- pos=i+j;
- }
- }
- if(temp==virus.length() && pos<ans.size())
- ans.erase(ans.begin()+pos);
- }
- //cout<<ans.length()<<endl;
- if(ans.length()==0)
- {
- cout<<0<<endl;
- return 0;
- }
- else
- {
- cout<<ans<<endl;
- return 0;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement