Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
0 Ms 水果#include<iostream> #include<cstring> #include<cstdio> #include<string> #include<vector> using namespace std; char s1[102][31],s2[102][31]; int s,n,m,cnt; int c[102][102]; int p[102][102]; int flag; void LCS() { cnt=0; for(int i=1; i<n; i++) { for(int j=1; j<m; j++) { if(!strcmp(s1[i],s2[j])) { c[i][j]=c[i-1][j-1]+1; p[i][j]=1; } else { if(c[i-1][j]>c[i][j-1]) { c[i][j]=c[i-1][j]; p[i][j]=2; } else { c[i][j]=c[i][j-1]; p[i][j]=3; } } } } } void print(int i,int j) { if(p[i][j]==1) { print(i-1,j-1); printf("%s",s1[i]); if(flag) flag=0; else printf(" "); } else if(p[i][j]==2) { print(i-1,j); } else if(p[i][j]==3) { print(i,j-1); } } int main() { while(~scanf("%s",s1[1])) { n=1,m=0; while(scanf("%s",s1[++n]),s1[n][0]!='#') {} while(scanf("%s",s2[++m]),s2[m][0]!='#') {} memset(c,0,sizeof(c)); LCS(); flag=0; print(n-1,m-1); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator