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 |
用kmp写,wa了一晚上,最后发现。。。。。。尼玛原来用strstr也可以轻松水过orz。。代码来一发#include<stdio.h> #include<string.h> #include<iostream> #include<math.h> const int maxn=4050; char str[maxn][200]; int len[maxn]; int main() { int n; while(scanf("%d",&n)!=EOF&&n) { char temp[200]; char ans[200]; int max=0,t; int minnum=0; int min=10000; for(int i=1;i<=n;i++) { scanf("%s",str[i]); len[i]=strlen(str[i]); if(len[i]<min) { min=len[i]; minnum=i; } } //printf("%s\n",str[minnum]) for(int i=0;i<=min-2;i++) { for(int o=1;o<=min-i;o++) { /*if(min-i-o+1<max) break;*/ int k=0; //memset(temp,'\0',sizeof(temp)); for(int j=i;j<=min-o;j++) { temp[k++]=str[minnum][j]; } temp[k]='\0'; //printf("%s\n",temp); for(t=1;t<=n;t++) { if(t==minnum) continue; char *p=strstr(str[t],temp); if(p==NULL) { break; } } if(t==n+1) { if(k==max) { if(strcmp(ans,temp)>0) strcpy(ans,temp); } if(k>max) { max=k; strcpy(ans,temp); } } } } if(max==0) { printf("IDENTITY LOST\n"); } else { puts(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