标签:style blog http color io os java ar for
3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 3 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA 3 CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
no significant commonalities AGATAC CATCATCAT
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 char str[12][100]; 18 int n,fail[100],len = 60; 19 void getFail(char *s,int m) { 20 fail[0] = fail[1] = 0; 21 for(int i = 1; i < m; i++) { 22 int j = fail[i]; 23 while(j && s[i] != s[j]) j = fail[j]; 24 fail[i+1] = str[i] == str[j]?j+1:0; 25 } 26 } 27 bool kmp(char *s,int m,int k) { 28 getFail(s,m); 29 for(int i = 0,j = 0; i < len; i++) { 30 while(j && s[j] != str[k][i]) j = fail[j]; 31 if(str[k][i] == s[j]) { 32 j++; 33 if(j == m) return true; 34 } 35 } 36 return false; 37 } 38 int main() { 39 char tmp[100],ans[100]; 40 int i,j,k,t; 41 bool flag; 42 scanf("%d",&t); 43 while(t--) { 44 scanf("%d",&n); 45 flag = false; 46 for(i = 0; i < n; i++) 47 scanf("%s",str[i]); 48 len = strlen(str[0]); 49 strcpy(ans,str[0]); 50 for(i = len; i > 2 && !flag; i--) { 51 for(j = 0; j+i <= len; j++) { 52 strncpy(tmp,str[0]+j,i); 53 tmp[i] = ‘\0‘; 54 for(k = 1; k < n; k++) 55 if(!kmp(tmp,i,k)) break; 56 if(k == n) { 57 flag = true; 58 if(strcmp(ans,tmp) > 0) strcpy(ans,tmp); 59 else strcpy(ans,tmp); 60 } 61 } 62 } 63 flag?puts(ans):puts("no significant commonalities"); 64 } 65 return 0; 66 }
标签:style blog http color io os java ar for
原文地址:http://www.cnblogs.com/crackpotisback/p/3982696.html