标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 16142 | Accepted: 7189 |
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
暴力枚举长度,然后依次检查每个串是否匹配
1 /*by SilverN*/ 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cstdio> 6 #include<cmath> 7 using namespace std; 8 const int len=60; 9 char s[20][65]; 10 char cp[65]; 11 int n; 12 int main(){ 13 int i,j,k,T; 14 scanf("%d",&T); 15 int len; 16 while(T--){ 17 scanf("%d",&n); 18 char ans[100]; 19 memset(ans,‘\0‘,sizeof ans); 20 for(i=1;i<=n;i++)scanf("%s",s[i]); 21 for(i=1;i<=60;i++){ 22 int find=0; 23 for(j=0;j<=60-i;j++){ 24 len=0; 25 int check=1; 26 for(k=j; ;k++){ 27 cp[len++]=s[1][k]; 28 if(len==i)break; 29 } 30 cp[len]=‘\0‘; 31 for(k=2;k<=n;k++){ 32 if(!strstr(s[k],cp)){ 33 check=0; 34 break; 35 } 36 } 37 if(check){ 38 find=1; 39 if(strlen(ans)<strlen(cp)) strcpy(ans,cp); 40 else if(strcmp(ans,cp)>0) strcpy(ans,cp); 41 } 42 } 43 if(!find)break; 44 } 45 if(strlen(ans)<3) printf("no significant commonalities\n"); 46 else printf("%s\n",ans); 47 } 48 return 0; 49 }
标签:
原文地址:http://www.cnblogs.com/SilverNebula/p/5677369.html