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 |
cpp真恶心。。害的我换了好几个编译器。真郁闷。 #include <stdio.h> #include <string.h> using namespace std; char a[200],b[200],ch; int i,j,n,m,len,ans; int f[200][200]; int main(){ while((ch=getchar())!='0'){ n=1; a[n]=ch; while((ch=getchar())!='\n'){ ++n; a[n]=ch; }; m=0; while((ch=getchar())!='\n'){ ++m; b[m]=ch; }; memset(f,0,sizeof(f)); for(i=1;i<=n;++i) for(j=1;j<=m;++j){ f[i][j]=f[i-1][j]>f[i][j-1]?f[i-1][j]:f[i][j-1]; if(a[i]==b[j]&&f[i][j]<f[i-1][j-1]+1) f[i][j]=f[i-1][j-1]+1; }; len=f[n][m]; if(m<n){ j=m; m=n; n=j; }; len=n-len; ans=0; while(len>n-len||(n-len)*2<m){ ++ans; n*=2; } ++ans; printf("%d\n",ans); }; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator