POJ - 3080 Blue Jeans

Posted 西北会法语

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ - 3080 Blue Jeans相关的知识,希望对你有一定的参考价值。

The Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thousands of contributors to map how the Earth was populated.

As an IBM researcher, you have been tasked with writing a program that will find commonalities amongst given snippets of DNA that can be 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 are found in the molecule. There are 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 will 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 <= 10) indicating the number of base sequences in this dataset.
  • m lines each containing a single base sequence consisting of 60 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" instead. If multiple subsequences of the same longest length exist, output only the subsequence that comes first in alphabetical order.

Sample Input

3
2
GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
3
GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA
GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
3
CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

Sample Output

no significant commonalities
AGATAC
CATCATCAT
用头文件《cstring》里面的一些库函数即可。
 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<algorithm>
 5 
 6 using namespace std;
 7 
 8 char s[15][65];
 9 char goal[65],now[65];
10 
11 int main()
12 {
13     int T,n;
14     scanf("%d",&T);
15     while(T--)
16     {
17         //int flag=0;
18         memset(goal,\0,sizeof(goal));
19         memset(now,\0,sizeof(now));
20         memset(s,\0,sizeof(s));
21         scanf("%d",&n);
22         for(int i=0;i<n;i++)
23             scanf("%s",s[i]);
24         for(int i=1;i<=60;i++)
25         {
26             for(int j=0;j<=60-i;j++)
27             {
28                 int len =0;
29                 int check=1;
30                 for(int k=j;;k++)
31                 {
32                     now[len++]=s[0][k];
33                     if(len==i)
34                         break;
35                 }
36                 now[len]=\0;
37                 for(int k=1;k<n;k++)
38                     if(!strstr(s[k],now))
39                     {
40                         check=0;
41                         break;
42                     }
43                 if(check==1)
44                 {
45                     if(strlen(goal)<strlen(now))
46                         strcpy(goal,now);
47                         else if(strcmp(goal,now)>0)
48                             strcpy(goal,now);
49                 }
50             }
51         }
52         if(strlen(goal)<3)
53             printf("no significant commonalities\n");
54         else
55             printf("%s\n",goal);
56     }
57     
58     return 0;
59 }

 

以上是关于POJ - 3080 Blue Jeans的主要内容,如果未能解决你的问题,请参考以下文章

POJ - 3080 Blue Jeans

POJ - 3080 Blue Jeans

(kmp)poj 3080 ——Blue Jeans

poj3080 Blue Jeans(暴枚+kmp)

Match:Blue Jeans(POJ 3080)

POJ 3080 - Blue Jeans