Blue Jeans

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个DNA序列,每个DNA序列长度都为60。

    找到最长共有子序列。

    PS1:若长度相同输出字典序最小的

    PS2:若最长子序列长度小于2,则输出no significant commonalities

解题思路:

    暴力枚举第一个DNA序列的每一个子序列,用strstr()函数与2-N序列进行匹配。

Code:

 #include<stdio.h>
#include<string>
#include<cstring>
#include<iostream>
using namespace std;
char str[][];
void cpy(char *tmp,int i,int j)
{
int t=,k;
for (k=i; k<=j; k++)
tmp[t++]=str[][k];
tmp[t]=;
}
void cmp(char *ans,char *tmp)
{
if (strlen(ans)<strlen(tmp)) strcpy(ans,tmp);
else if (strlen(ans)==strlen(tmp)&&strcmp(ans,tmp)>)
strcpy(ans,tmp);
}
int main()
{
int T;
cin>>T;
while (T--)
{
int N;
char tmp[];
cin>>N;
char ans[]= {};
for (int i=; i<=N; i++)
cin>>str[i];
for (int i=; i<=; i++)
for (int j=i; j<=; j++)
{
cpy(tmp,i,j);
int k;
for (k=; k<=N; k++)
if (strstr(str[k],tmp)==NULL) break;
if (k==N+)
cmp(ans,tmp);
}
if (strlen(ans)>=) printf("%s\n",ans);
else printf("no significant commonalities\n");
}
return ;
}

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【KMP】【暴力】

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

  3. kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans

    The Genographic Project is a research partnership between IBM and The National Geographic Society th ...

  4. POJ3080 Blue Jeans 题解 KMP算法

    题目链接:http://poj.org/problem?id=3080 题目大意:给你N个长度为60的字符串(N<=10),求他们的最长公共子串(长度>=3). 题目分析:KMP字符串匹配 ...

  5. codeM编程大赛E题 (暴力+字符串匹配(kmp))

    题目大意:S(n,k)用k(2-16)进制表示1-n的数字所组成的字符串,例如S(16,16)=123456789ABCDEF10: 解题思路: n最大50000,k最大100000,以为暴力会超时. ...

  6. POJ3080 - Blue Jeans(KMP+二分)

    题目大意 求N个字符串的最长公共字串 题解 和POJ1226做法一样...注意是字典序最小的...WA了一次 代码: #include <iostream> #include <cs ...

  7. POJ3080 Blue Jeans

    题目链接. 题目大意: 给定n个字符串,找出最长相同且长度大于3的子串,如果存在多个,找出字典序最小的. 分析: 直接枚举(暴搜). 对于s[0]的每一个子串,判断是否在其它n-1个字符串中都存在. ...

  8. poj 3080 Blue Jeans (暴力枚举子串+kmp)

    Description The Genographic Project is a research partnership between IBM and The National Geographi ...

  9. poj3080 Blue Jeans(暴枚+kmp)

    Description The Genographic Project is a research partnership between IBM and The National Geographi ...

随机推荐

  1. 为mapcontrol中的图层设置透明度

    ILayer pLayer = axMapControl1.get_Layer(); ILayerEffects pLayerEffects = (ILayerEffects)pLayer; pLay ...

  2. undrop for innodb c_parser 不完美之处

    今天发现c_parser导出数据是会丢掉某些行,给过调试发现是他处理utf8编码时计算有误,目前还没有发现自动解决总是的方法,只会手动改代码来解决. 下一步计划把c_parser移植到windows下 ...

  3. DEDECMS中,获取当前栏目名称

    获取当前栏目名称 {dede:field name='typeurl' function=”GetTypeName(@me)”/} 指的是当前栏目的URL地址 {dede:field name='ty ...

  4. 安装MySQL总结

    由于MySQL的版本不同,所以会有不同的安装方式.在下以Linux系统下MySQL5.1.19版本为例,进行安装,初学还望指正. 一.安装编译软件(简单的yum安装) gcc gcc-c++ ncur ...

  5. L004-oldboy-mysql-dba-lesson04

        L004-oldboy-mysql-dba-lesson04 [root@web01 mysql]# mysql -uroot -ptestpassword -S /tmp/mysql.soc ...

  6. jQuery 全选 反选 单击行改变背景色

    我先把CSS样式放出来,其实这个可以直接忽略 ;;font-size:12px;font-family:微软雅黑;} .datagrid{width:100%;} .datagird tr th{ba ...

  7. PHP中使用多线程

    <?php while(1)//循环采用3个进程 { //declare(ticks=1); $bWaitFlag= FALSE; // 是否等待进程结束 //$bWaitFlag = TRUE ...

  8. 3、WPF学习之-布局

    一.基础知识 1.所有WPF布局容器都派生自System.Windows.Controls.Panel抽象类的面板: 2.WPF种核心布局面板有StackPanel(栈面板).WrapPanel(环绕 ...

  9. Who needs an architect?---Martin Fowler

    英文及译文下载链接:http://pan.baidu.com/share/link?shareid=163291504&uk=1428554614 1.文章主题总结 首先我们从文章的几个小标题 ...

  10. C++ 字符串各种处理

    要想使用标准C++中string类,必须要包含 #include <string>// 注意是<string>,不是<string.h>,带.h的是C语言中的头文件 ...