Blue Jeans
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 14283 |
|
Accepted: 6356 |
Description The Genographic Project is a, the partnership between IBM and the National Geographic Society, is a Nalyzing DNA from hundreds of thousands of contributors to map how the Earth was populated.
As an IBM researcher been tasked with writing a program that would find commonalities amongst given SNI Ppets of DNA that can is correlated with individual survey information to identify new genetic markers.
A DNA Base sequence is noted by listing the nitrogen bases in the order in which they be found in the molecule. There is four bases:adenine (A), thymine (T), guanine (G), and cytosine (C). A 6-base DNA sequence could be represented as TAGACC.
Given A set of DNA base sequences, determine the longest series of bases that occurs in all of the sequences.
Input input to this problem would begin with a line containing a single integer n indicating the number of datasets. Each dataset consists of the following components:a single positive integer m (2 <= m <=) indicating the number Of base sequences in the This dataset. M lines each containing a single base sequence consisting of bases.
Output for each dataset in the input, output the longest base subsequence common to all of the given base sequences. If the longest common subsequence is less than three bases in length, display the string "no significant commonalities" in Stead. If multiple subsequences of the same longest length exist, output only the subsequence that comes first in alphabetical or Der.
Sample Input
3
2
gataccagataccagataccagataccagataccagataccagataccagataccagata
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
3
Gataccagataccagataccagataccagataccagataccagataccagataccagata
GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
3
CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Aacatcatcatttttttttttttttttttttttttttttttttttttttttttttttttt
Sample Output
No significant commonalities
Agatac
catcatcat
Test instructions: Find the largest contiguous common substring of multiple sets of strings, if the length is less than three output "no significant commonalities", otherwise, for the output of the common substring, for the same length of the common substring, the output alphabetical order of the smaller string
Thoughts: Mob Search
#include <cstdio> #include <iostream> #include <cstring> using namespace std;
Char a[15][65];
Char anss[65];
int main () {int n;
scanf ("%d", &n);
while (n--) {int m;
scanf ("%d", &m);
int i,j,k;
for (i=0;i<m;i++) {scanf ("%s", A[i]);
} int ans=0;
int Len=strlen (a[0]);
Char sub[65];
for (i=0;i<len;i++) {for (j=i+2;j<len;j++) {strncpy (sub,a[0]+i,j-i+1);
sub[j-i+1]= ' + ';
int flag=1;
for (k=1;flag&&k<m;k++) {if (Strstr (a[k],sub) ==0) {flag=0; }} if (flag&& (Ans<strlen (sub) | | (Ans==strlen (sub) &&strcmp (anss,sub) >=0)))
{//Remember to compare Ans=strlen (sub);
strcpy (anss,sub);
}}} if (ans<3) printf ("no significant commonalities"); else PrinTF ("%s", ANSS);
printf ("\ n"); }
}