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 |
老是re 显然是输入问题 大牛指点下#include<iostream> #include<string> using namespace std; int main() { char a[500]; char b[500]; int c[500][500]; char ch; int i,j,n,m; ch=getchar(); while(ch!='\n') { i=1; n=0; while(ch!=' ') { a[i]=ch; i++; n++; ch=getchar(); } ch=getchar(); i=1; m=0; while(ch!='\n') { b[i]=ch; i++; m++; ch=getchar(); } for(i=0;i<=n;i++) c[i][0]=0; for(j=0;j<=m;j++) c[0][j]=0; for(i=1;i<=n;i++) for(j=1;j<=m;j++) { if(a[i]==b[j]) c[i][j]=c[i-1][j-1]+1; else { c[i][j]=(c[i][j-1]>c[i-1][j])?c[i][j-1]:c[i-1][j]; } } cout<<c[n][m]<<endl; ch=getchar(); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator