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 |
暴力过的(0ms),代码贴一下!# include<stdio.h> # include<string.h> int main() { int i,j,n,m,k,h,num,ans,len; char str[20][65],st[65],s[65]; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&m); getchar(); for(j=0;j<m;j++) gets(str[j]); len=strlen(str[0]); ans=0; for(j=0;j<len;j++) { for(k=j;k<len;k++) { num=0; for(h=j;h<=k;h++) st[num++]=str[0][h]; st[num]=0; for(h=1;h<m;h++) if(strstr(str[h],st)==0) break; if(h==m&&ans<num) { ans=num; strcpy(s,st); } else if(h==m&&ans==num) { if(strcmp(s,st)>0) strcpy(s,st); } } } if(ans<3) printf("no significant commonalities\n"); else puts(s); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator