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 |
超时代码求帮改#include<stdio.h> #include<string.h> int count1,k; int compare(char str1[1000004],char str[1000004]) { int k1,i,j,a=1; k1=strlen(str1); for(i=k1;i<k;) { j=0; while(j<k1&&str1[j]==str[i++])j++; if(j!=k1)return 0; else a++; } if(i==k)return a; else return 0; } int main(void) { char str[1000004],str1[1000004]; int i,sum; while(scanf("%s",str)!=EOF) { if(strcmp(str,".")==0)break; sum=0; k=strlen(str); for(i=0;i<k;i++) { str1[i]=str[i];str1[i+1]='\0'; count1=compare(str1,str); if(sum<count1){sum=count1;break;} } printf("%d\n",sum); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator