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 |
大神请指导一下,为什么总是超时,不管是C++还是G++!!!跪求速解!!!小生代码: #include<cstdio> #include<iostream> #include<cstring> #define M 10010 #define N 15 using namespace std; char ch[M][N],s[N]; int a[M]; int search(char *a,char *b) { int lena=strlen(a); int lenb=strlen(b); if(lena==lenb) { int flag=0; for(int i=0;i<lena;i++) if(a[i]!=b[i]) if(!flag) flag=1; else return 0; if(flag==1)return 1; } if(lena==lenb+1) { int pa=0,pb=0,flag=0; while(1) { if(pa>=lena&&pb>=lenb)break; if(a[pa]==b[pb]) { pa++; pb++; } else if(!flag) { flag=1; pa++; } else return 0; } if(flag==1)return 1; } if(lena==lenb-1) { int pa=0,pb=0,flag=0; while(1) { if(pa>=lena&&pb>=lenb)break; if(a[pa]==b[pb]) { pa++; pb++; } else if(!flag) { flag=1; pb++; } else return 0; } if(flag==1)return 1; } return 0; } int main() { int n=0; while(1) { scanf("%s",ch[++n]); if(ch[n][0]=='#') { n--; break; } } while(1) { int flag=0,cnt=0; scanf("%s",s); if(s[0]=='#')break; printf("%s",s); for(int i=1;i<=n;i++) { if(strcmp(s,ch[i])==0) { printf(" is correct\n"); flag=1; break; } else if(search(s,ch[i])) a[++cnt]=i; } if(!flag) { printf(":"); for(int i=1;i<=cnt;i++) printf(" %s",ch[a[i]]); printf("\n"); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator