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. VS2008试用版到期解决办法

    在Windows 7下,VS2008试用版无法正常升级到正式版.原因是维护页面的注册码输入框和升级按钮被隐藏.通过本补丁,可让注册码输入框和升级按钮恢复正常显示 点击此处下载补丁 1.安装完90天试用 ...

  2. NPM环境搭建

    1. NPM全局路径:配置npm包的安装位置,在你的用户文件夹下,新建.npmrc文件:cache=D:\NodeJs\nvm\npm-cache 表示缓存文件夹 prefix=D:\NodeJs\n ...

  3. SCXML和QScxml使用总结

    最近接触了SCXML这个状态描述文本,简单来讲就是描述了整个状态的变迁过程的一种XML格式的表格.Qt labs中有一个项目就是QScxml,它基于QStateMachine上层制作,可以直接读取SC ...

  4. jquery mobile listview列表属性(搜索自动填充检索效果)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  5. JDBC驱动汇总

    Microsoft SQL Server (6.5, 7, 2000 and 2005) and Sybase (10, 11, 12).   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...

  6. typedef , static和 extern

    typedef 1.作用:给已经存在的类型起一个新的名称 2.使用场合: 1> 基本数据类型 2> 指针 3> 结构体 4> 枚举 5> 指向函数的指针 #include ...

  7. Equivalent Strings (字符串相等?)

    Equivalent Strings   E - 暴力求解.DFS Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I ...

  8. 大数据学习之hadoop伪分布式集群安装(一)公众号undefined110

    hadoop的基本概念: Hadoop是一个由Apache基金会所开发的分布式系统基础架构. 用户可以在不了解分布式底层细节的情况下,开发分布式程序.充分利用集群的威力进行高速运算和存储. Hadoo ...

  9. 我的sublime常用快捷键

    sublime一般被应用于前端开发,在实际开发中,我们常用的sublime快捷键有哪些呢?这里汇总一下,常用的排在前面. 常用快捷键 Ctrl+Shift+P:打开命令面板 Ctrl+D:选择重复单词 ...

  10. xcode改名称、路径后要在终端中设置路径

    打印xcode位置: xcode-select -print-path 重新设置xcode位置 sudo xcode-select -switch /Applications/Xcode/Xcode6 ...