http://poj.org/problem?id=3080
Description
Input
Output
Sample Input
3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 3 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA 3 CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
Sample Output
no significant commonalities AGATAC CATCATCAT
///#pragma comment (linker, "/STACK:102400000,102400000") #include <iostream> #include <queue> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <cstdlib> #include <limits> #include <stack> #include <vector> #include <map> using namespace std; #define N 100 #define INF 0xfffffff #define PI acos (-1.0) #define EPS 1e-8 #define met(a, b) memset (a, b, sizeof (a)) char str[N][N]; int n; bool Judge (char sub[]); int main () { int t; scanf ("%d", &t); while (t--) { scanf ("%d", &n); for (int i=0; i<n; i++) scanf ("%s", str[i]); int flag = 0; char s1[N], s[N], sub[N]; int len = strlen (s1), len1 = 0; met (s, 0); strcpy (s1, str[0]); for (int i=len; i>=1; i--) { for (int j=0; j<=len-i; j++) { met (sub, 0); strncpy (sub, s1+j, i); if (Judge (sub)) { if (!flag) { strcpy (s, sub); len1 = strlen (s); flag = 1; } else if (strlen (sub) == len1 && strcmp (s, sub)) strcpy (s, sub); } } } if (len1 < 3) puts ("no significant commonalities"); else puts (s); } return 0; } bool Judge (char sub[]) { for (int i=1; i<n; i++) if (strstr (str[i], sub) == NULL) return false; return true; } /* 3 2 ASDFG SDFGH */