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 |
For help!!! 那位同仁帮我检查一下这个程序为什么会超时...谢谢啊#include"stdio.h" #include"string.h" void main() { int n,i,m,r1,r2,q,j,r,k,p1; char a[11][81],b[11][81],s[260],*p; while(1) { q=0; scanf("%d%*c",&n);if(n==0) break; for(i=0;i<n;i++) {gets(a[i]);gets(b[i]);} gets(s); while(1) { m=strlen(s); q=1; for(i=0;i<n;i++) { k=0; p=strstr(s,a[i]); if(p!=NULL) { q=0; p1=(int)(p-s); r1=strlen(a[i]); r2=strlen(b[i]); r=r2-r1; if(r>0) for(j=m+r-1;j>=p1+r2;j--) s[j]=s[j-r]; else if(r<0) for(j=p1+r2;j<m+r;j++) s[j]=s[j-r]; s[m+r]='\0'; for(j=p1;j<p1+r2;j++) s[j]=b[i][k++]; break; } } if(q==1)break; } puts(s); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator