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

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

Sample Output

no significant commonalities
AGATAC
CATCATCAT
找出n个串中最长的公共串,并且要求字典序最大
直接枚举第一串的所有子串,然后与后面的所有串进行比较即可
 
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; char str[15][65];
char sub[65];
char ans[65];
int len; int main()
{
int t,i,j,k,n,maxn;
scanf("%d",&t);
while(t--)
{
maxn = 0;
scanf("%d",&n);
memset(ans,'\0',sizeof(ans));
for(i = 1; i<=n; i++)
scanf("%s",str[i]);
for(i = 1; i<=60; i++)
{
int find = 0;
for(j = 0; j<=60-i; j++)
{
len = 0;
int check = 1;
for(k = j;;k++)
{
sub[len++] = str[1][k];
if(len == i)
break;
}
sub[len] = '\0';
for(k = 2; k<=n; k++)
{
if(!strstr(str[k],sub))
{
check = 0;
break;
}
}
if(check)
{
find = 1;
if(strlen(ans)<strlen(sub))
strcpy(ans,sub);
else if(strcmp(ans,sub)>0)
strcpy(ans,sub);
}
}
if(!find)
break;
}
if(strlen(ans)<3)
printf("no significant commonalities\n");
else
printf("%s\n",ans);
} return 0;
}

POJ3080:Blue Jeans的更多相关文章

  1. POJ3080 Blue Jeans —— 暴力枚举 + KMP / strstr()

    题目链接:https://vjudge.net/problem/POJ-3080 Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total ...

  2. POJ3080——Blue Jeans(暴力+字符串匹配)

    Blue Jeans DescriptionThe Genographic Project is a research partnership between IBM and The National ...

  3. poj3080 Blue Jeans【KMP】【暴力】

    Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:21746   Accepted: 9653 Descri ...

  4. POJ 3080 Blue Jeans (字符串处理暴力枚举)

    Blue Jeans  Time Limit: 1000MS        Memory Limit: 65536K Total Submissions: 21078        Accepted: ...

  5. POJ 3080 Blue Jeans(Java暴力)

    Blue Jeans [题目链接]Blue Jeans [题目类型]Java暴力 &题意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 规定: 1. 最长公共 ...

  6. (字符串 KMP)Blue Jeans -- POJ -- 3080:

    链接: http://poj.org/problem?id=3080 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88230#probl ...

  7. POJ 3080 Blue Jeans 找最长公共子串(暴力模拟+KMP匹配)

    Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20966   Accepted: 9279 Descr ...

  8. POJ Blue Jeans [枚举+KMP]

    传送门 F - Blue Jeans Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  9. POJ 3080 Blue Jeans (求最长公共字符串)

    POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...

随机推荐

  1. Sql语句 不支持中文 国外数据库

    由于老美的不支持中文 SQL 语句第一:字段类型改为nvarchar,ntext 第二:强制转化 N update dbo.Role set rolename=N'普通用户' update dbo.T ...

  2. project facet java version 1.6 is not supported

    可能你用的jdk1.5的包,而开发是用的jdk1.6,不允许1.5进行安装 法1,选中项目 Properties , 选择 Project Facets,右击选择 Java , Change Vers ...

  3. eclipse打包jar时包含第三方jar包的相关问题

    我用的是mars4.5版本的eclipse 需求:要把写好的工程打成jar包,并能直接运行.工程用了若干个第三方jar. 在打包的时候,eclipse提供的打包方法不能引用第三方jar包,导致了出现C ...

  4. C# 深入浅出 委托与事件

    C#中的委托和事件的概念接触很久了,但是一直以来总没有特别透彻的感觉,现在我在这里总结一下: 首先我们要知道委托的由来,为什么要使用委托了? 我们先看一个例子: 假设我们有这样一个需求,需要计算在不同 ...

  5. USACO5.4-TeleCowmunication

    题目大意:给出一个无向图,要求删除尽量少的点,使给定的2点间不再连通,并输出字典序最小的方案题型:图论-网络流此题难点在于建图,后面就是套网络流的模板.将点看成边,例如第i个点可以看成一条有向边< ...

  6. 【USACO 2.3.1】最长前缀

    [题目描述] 在生物学中,一些生物的结构是用包含其要素的大写字母序列来表示的.生物学家对于把长的序列分解成较短的序列(即元素)很感兴趣. 如果一个集合 P 中的元素可以通过串联(元素可以重复使用,相当 ...

  7. 初涉JavaScript模式 (10) : 函数 【进阶用法】

    写在前面 不知不觉写到第10篇了.这篇写起来很忐忑,终于和高级搭上边了(呵呵),这篇我们 主要 说一下 JS 方法的部分高级用法(我知道的),笔者水平有限,难免有错.废话不多少,进入正文. 初始化 我 ...

  8. c++builder向c#开发的webservice传递非数字参数

    一.引用WebService地址 BCB6.0环境下,File-New-Other-WebService-WSDL Importer.然后手动写完整地址.如:“http://192.168.1.3:1 ...

  9. 在sublimetext上打造一个兼容virtualenv的web&python开发环境

    利用Sublimetext3&virtualenv 打造一个Web&Python IDE 注: 环境:window|python3;以下使用的sublimetext插件均用packag ...

  10. uva 10976 Fractions Again(简单枚举)

    10976 Fractions Again It is easy to see that for every fraction in the form 1 k (k > 0), we can a ...