标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 14303 | Accepted: 6367 |
Description
Input
Output
Sample Input
3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 3 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA 3 CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
Sample Output
no significant commonalities AGATAC CATCATCAT
Source
Problem: 3080 User: kxh1995 Memory: 136K Time: 32MS Language: C++ Result: Accepted
#include<string.h> #include<stdio.h> #include<stdlib.h> char str[20][70]; int next[100],flag; void getnext(char *s) { int len=strlen(s); int j=0,k=-1; next[0]=-1; while(j<=len) { if(k==-1||s[k]==s[j]) { k++; j++; next[j]=k; } else k=next[k]; } } int kmp(char *a,char *b) { int i,j; i=j=0; int n=strlen(a); int m=strlen(b); getnext(b); while(i<n) { if(j==-1||a[i]==b[j]) { i++; j++; } else j=next[j]; if(j==m) return 1; } return 0; } int main() { int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); int i,j,k; for(i=0;i<n;i++) { scanf("%s",str[i]); } int len=strlen(str[0]); char temp[70],ans[70]=""; //flag=0; for(i=0;i<len;i++) { int cnt=0; for(j=i;j<len;j++) { temp[cnt++]=str[0][j]; temp[cnt]='\0'; int flag=0; for(k=1;k<n;k++) { if(!kmp(str[k],temp)) { flag=1; break; } } if(!flag) { if(strlen(temp)>strlen(ans)||(strlen(temp)==strlen(ans)&&strcmp(temp,ans)<0)) memcpy(ans,temp,sizeof(temp)); } } } if(strlen(ans)<3) { printf("no significant commonalities\n"); } else printf("%s\n",ans); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/yu_ch_sh/article/details/47731757