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. GIS初学者

    学习编程一直以来没有什么好的思路,感觉就是学了忘,忘了再重复,效率特别低下.大概是从大三第一学期才有意识的转向c#的学习,来熟悉VS2010平台,在这之前我都不知道自己是怎么学习的. 大一第二学期开的 ...

  2. IIS安装Web Deploy之后没有显示右键菜单

    Bug描述: 使用IIS自带的"Web平台安装程序"安装完Web Deploy组件之后,鼠标右键点击网站,弹出的菜单中并没有新增的"部署"选项. Bug解决: ...

  3. 基于TLS的反调试技术

    TLS(Thread Local Storage 线程局部存储) 一个进程中的每个线程在访问同一个线程局部存储时,访问到的都是独立的绑定于该线程的数据块.在PEB(进程环境块)中TLS存储槽共64个( ...

  4. SQL Server如何使用XML格式传输解析

    Sqlserver in 实现 参数化查询 XML类型解决方案 [转] :如果参数是int类型: declare @a xml set @a=' <row><id>1</ ...

  5. PHPExcel读取excel03/07版到数组

    想总结下PHPExcel的读取excel到数组的function,用的时候直接调取,懒…… 参考了以下链接: http://www.jb51.net/article/29071.htm http:// ...

  6. UVA 725

    Description   Write a program that finds and displays all pairs of 5-digit numbers that between them ...

  7. web sevice 生成代理类及使用

    一.生成代理类: VS2008下这样写 wsdl.exe /l:cs /out:D:/ProxyServices.cs http://localhost/WebService.asmx VS2010下 ...

  8. 编译升级php

    http://www.linux-centos.com/2014/11/16/%E7%BC%96%E8%AF%91%E5%8D%87%E7%BA%A7%E4%BB%8Ephp5-2-17%E5%88% ...

  9. c# 赋值后最后一项数据部分丢失

    赋值,赋值后 原因,在添加后立即调用clear()清除数据....

  10. 用火狐打开PDF文件

    可以直接使用官方的Adobe Reader插件来实现在火狐中浏览PDF文件的功能.在你浏览一个PDF文件的时候,火狐将会尝试下载安装这个插件. 如果这个插件出现问题,那么就无计可施啦. 检查火狐的设置 ...