Blue Jeans
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 16142 |
|
Accepted: 7189 |
Description
The genographic Project is a, partnership between IBM and the National Geographic Society, is analyzing DN A from hundreds of thousands of contributors to map how the Earth was populated.
as an IBM researcher, you had been tasked with writing a program that would find commonalities amongst given snippets 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 was 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 An integer m (2 <= m <=) indicating the number of the base sequences in 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
32GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA A3gataccagataccagataccagataccagataccagataccagataccagataccagatagatactagatactagatactagatactaaaggaaagggaaaaggggaaaaagggggaaa Agataccagataccagataccagataccaaaggaaagggaaaaggggaaaaagggggaaaa3catcatcatcccccccccccccccccccccccccccccccccccccccccccccccccc Cacatcatcataaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacatcatcatttttttttttttttttttttttttttttttttttttttttttttttttt
Sample Output
No significant commonalitiesagataccatcatcat
Source
South Central USA 2006
Brute-force enumeration length, and then check to see if each string matches
1 /*by Silvern*/2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cstdio>6#include <cmath>7 using namespacestd;8 Const intlen= -;9 Chars[ -][ $];Ten Charcp[ $]; One intN; A intMain () { - inti,j,k,t; -scanf"%d",&T); the intLen; - while(t--){ -scanf"%d",&n); - Charans[ -]; +memset (ans,' /',sizeofans); - for(i=1; i<=n;i++) scanf ("%s", S[i]); + for(i=1; i<= -; i++){ A intFind=0; at for(j=0; j<= --i;j++){ -len=0; - intcheck=1; - for(k=j;; k++){ -cp[len++]=s[1][k]; - if(len==i) Break; in } -cp[len]=' /'; to for(k=2; k<=n;k++){ + if(!strstr (S[K],CP)) { -check=0; the Break; * } $ }Panax Notoginseng if(check) { -Find=1; the if(Strlen (ANS) <strlen (CP)) strcpy (ANS,CP); + Else if(strcmp (ANS,CP) >0) strcpy (ANS,CP); A } the } + if(!find) Break; - } $ if(Strlen (ANS) <3) printf ("no significant commonalities\n"); $ Elseprintf"%s\n", ans); - } - return 0; the}
POJ3080 Blue Jeans