poj 3080 Blue Jeans 暴力

Blue Jeans

Time Limit: 1000MSMemory Limit: 65536K

Total Submissions: 14283Accepted: 6356

Description

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

32GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATAGATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAAGATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA3CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

Sample Output

no significant commonalitiesAGATACCATCATCAT

题意: 求出多组字符串的最大相邻公共子串,若长度小于三则输出“no significant commonalities”,,否则,对于输出公共子串,对于同样长度的公共子串,输出按字母排序较小的串

思路:暴搜暴搜暴搜~~~#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]='\0';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))){//记得比较一下ans=strlen(sub);strcpy(anss,sub);}}}if(ans<3) printf("no significant commonalities");elseprintf("%s",anss);printf("\n");}}

版权声明:本文为博主原创文章,未经博主允许不得转载。

『 不可能 』只存在於蠢人的字典里

poj 3080 Blue Jeans 暴力

相关文章:

你感兴趣的文章:

标签云: