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. UVaLive 7361(矩阵快速幂)

    题意:矩阵快速幂求斐波那契数列. 分析:

  2. MySQL忘记密码后重置密码(Mac )

    安装好MySQL以后,系统给了个默认的的密码,然后说如果忘记了默认的密码......我复制了默认密码就走过了这一步,这一步就是我漫长旅程的开始.他给的密码太复杂了,当然我得换一个,而且我还要假装我不记 ...

  3. ubuntu grub 引导修复

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4167644.html   (1) 先使用ls命令,找到Ubuntu的安装分区: 在 grub ...

  4. windows github 搭建与使用

    git/github使用以下是全部在命令行使用(windows/github) 注册账户以及创建仓库先在github建立账号和创建仓库,此时为空的仓库 配置git下载并安装 git windows版本 ...

  5. [C#]AccessUtils

    关键代码: using System; using System.Data; using System.Data.OleDb; namespace CSharpUtilHelpV2 { /// < ...

  6. php安全设定

    nginx: 在配置文件nginx.conf的http段里加入  server_tokens off;  HTTPD.CONFTraceEnable Off <Directory ~ " ...

  7. 手写一个自己的简单MVC框架myPHP

    myPHP框架 采用的是MVC 思想,应用纯面向对象及项目单一入口,实现的一个自定义的框架.(自己兴趣的练习) 一.项目单一入口 入口文件 myphp\index.php前台 一个网站所有的请求都请求 ...

  8. php代码加密|PHP源码加密——实现方法

    Encipher - PHP代码加密 | PHP源码加密下载地址:https://github.com/uniqid/encipher 该加密程序是用PHP代码写的,加密后代码无需任何附加扩展,无需安 ...

  9. php入门常量

    常量像变量一样,用于临时存储一个值,但是常量在许多方面与变量不同. 常量:1.是在程序执行期间无法改变数据,常量的作用域是全局的.2.常量的命名与与变量相似,只是不带美元符号“$”.一个有效的常量名由 ...

  10. discuz X2.5自己写代码,获取当前登录的用户信息

    <? //这个只是获取当前用户账号以及积分的方法,同样你修改SQL语句可以实现discuz所有数据处理的功能 require '../source/class/class_core.php';/ ...