Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 12233 | Accepted: 5307 |
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
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int mm[100][100] ; char s[100][100] , str1[100] , str2[100] ; int f(int i,int j,int k,int num) { int ii , jj , ll ,flag; ll = strlen(s[k]); memset(mm,0,sizeof(mm)); flag = 0 ; for(ii = i ; ii <= j ; ii++) { for(jj = 0 ; jj < ll ; jj++) { if(ii == i || jj == 0) { if( s[0][ii] == s[k][jj] ) mm[ii][jj] = 1 ; } else { if( s[0][ii] == s[k][jj] ) mm[ii][jj] = 1 ; if( mm[ii][jj] ) mm[ii][jj] += mm[ii-1][jj-1] ; if( mm[ii][jj] == num ) flag = 1 ; } } } if( flag ) return 1 ; else return 0 ; } int main() { int t , n , i , j , l , ll , k , num , flag , max1 , a , b ; scanf("%d", &t); while(t--) { scanf("%d", &n); for(i = 0 ; i < n ; i++) scanf("%s", s[i]); l = strlen(s[0]); max1 = 0 ; for(i = 0 ; i < l ; i++) { for(j = l-1 ; j-2 >= i ; j--) { num = j - i + 1 ; for(k = 1 ; k < n ; k++) { if( !f(i,j,k,num) ) break; } if(k == n ) { if(num > max1) { max1 = num ; for(a = 0 ; a < num ; a++) str1[a] = s[0][a+i] ; str1[a] = '\0' ; } else if( num == max1 ) { for(a = 0 ; a < num ; a++) str2[a] = s[0][a+i] ; str2[a] = '\0' ; if( strcmp(str1,str2) > 0 ) strcpy(str1,str2); } } } } if( max1 < 3 ) printf("no significant commonalities\n"); else { printf("%s\n", str1); } } return 0; }