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 |
下面是我的代码,为啥会Output Limit Exceeded?!望神牛指点迷津!#include<stdio.h> #include<string.h> int main(){ char a[100][30],b[100][30]; int com[100][100],sign[100][100],flag[100]; int n,na,nb,i,j; while(1){ for(i=0;i<100;i++) flag[i]=0; na=nb=0; while(scanf("%s",a[na])&&a[na][0]!='#') na++; while(scanf("%s",b[nb])&&b[nb][0]!='#') nb++; for(i=0;i<=na;i++) com[i][0]=sign[i][0]=0; for(j=0;j<=nb;j++) com[0][j]=sign[0][j]=0; for(i=1;i<=na;i++) for(j=1;j<=nb;j++) if(strcmp(a[i-1],b[j-1])==0) { com[i][j]=com[i-1][j-1]+1;sign[i][j]=0;} else if(com[i-1][j]>com[i][j-1]) { com[i][j]=com[i-1][j];sign[i][j]=1;} else { com[i][j]=com[i][j-1];sign[i][j]=-1;} n=com[na][nb]; for(i=na,j=nb;i&&j;) if(!sign[i][j]) { flag[i-1]=1;i--;j--;} else if(sign[i][j]==1) i--; else j--; for(i=0;n>1;i++) if(flag[i]){ printf("%s ",a[i]); n--; } for(;;i++) if(flag[i]){ printf("%s\n",a[i]); break; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator