POJ 3080 Blue Jeans (字符串处理暴力枚举)
Blue Jeans
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 21078 Accepted: 9340
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
题意:找出给定字符串中都存在的最长的字典序最小的子串,若长度小于3,则输出no significant commonalities,否则输出该子串
思路:按长度递增的顺序,暴力枚举每个例子的第一个字符串的子串,然后通过strstr函数该子串验证是否存在于其他字符串中,每一步记录最长的子串,最后根据题意输出
#include<iostream>
#include<string.h>
using namespace std;
char s[11][66],str[66],ans[66];
int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%s",s[i]);
memset(ans,'\0',sizeof(ans));//后面求ans长度有用
for(int len=1;len<=60;len++)
{
int cnt=0;
for(int st=0;st<=60-len;st++)
{
for(int i=st;i<st+len;i++)//把一段字符串赋值给str
str[i-st]=s[0][i];
str[st+len]='\0';
int flag=1;
for(int i=1;i<n;i++)
if(!strstr(s[i],str)){//判断s[i]里面是否有str
flag=0;break;//一个不符合就退出该循环
}
if(flag)
{
cnt=1;
if(strlen(ans)<strlen(str))//取长的
strcpy(ans,str);
else if(strcmp(str,ans)<0)//取字典序小的
strcpy(ans,str);
}
}
if(!cnt)//短的都没有,长的肯定也没有
break;
}
if(strlen(ans)<3)
printf("no significant commonalities\n");
else
printf("%s\n",ans);
}
return 0;
}
POJ 3080 Blue Jeans (字符串处理暴力枚举)的更多相关文章
- POJ - 3080 Blue Jeans 【KMP+暴力】(最大公共字串)
<题目链接> 题目大意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 限制条件: 1. 最长公共串长度小于3输出 no significant co ...
- POJ 3080 Blue Jeans (求最长公共字符串)
POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...
- POJ 3080 Blue Jeans(Java暴力)
Blue Jeans [题目链接]Blue Jeans [题目类型]Java暴力 &题意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 规定: 1. 最长公共 ...
- POJ 3080 Blue Jeans 找最长公共子串(暴力模拟+KMP匹配)
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20966 Accepted: 9279 Descr ...
- poj 3080 Blue Jeans
点击打开链接 Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10243 Accepted: 434 ...
- 【POJ 3080 Blue Jeans】
Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 19026Accepted: 8466 Description The Genogr ...
- POJ 3080 Blue Jeans (多个字符串的最长公共序列,暴力比较)
题意:给出m个字符串,找出其中的最长公共子序列,如果相同长度的有多个,输出按字母排序中的第一个. 思路:数据小,因此枚举第一个字符串的所有子字符串s,再一个个比较,是否为其它字符串的字串.判断是否为字 ...
- poj 3080 Blue Jeans (暴力枚举子串+kmp)
Description The Genographic Project is a research partnership between IBM and The National Geographi ...
- poj 3080 Blue Jeans【字符串处理+ 亮点是:字符串函数的使用】
题目:http://poj.org/problem?id=3080 Sample Input 3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCA ...
随机推荐
- linux系统内核版本升级
一.查看Linux内核版本命令(2种方法): 1.cat /proc/version 2.uname -a 二.查看Linux系统版本的命令(3种方法): 1.lsb_release -a 即可列出所 ...
- python基础-----类和实例
在python中,首字母大写的名称指的是类,这个类定义中括号的内容是空的. 面向对象最重要的概念就是类(Class)和实例(Instance),必须牢记类是抽象的模板而实例是根据类创建出来的一个个具体 ...
- oracle查看未提交事务
SELECT s.sid, s.serial#, s.event, a.sql_text, a.sql_fulltext, s.username, s.status, s.machine, s.ter ...
- linux 制作U盘启动,和定制系统
找到u盘的路径 fdisk -l 将镜像写入u盘 dd if=/root/Downloads/kali-linux-2017.1-amd64.iso of=/dev/sdc 定制U盘启动系统: 安装完 ...
- 【转】python f-string
[转]python f-string 文章目录 1. 主要内容 1.1. 旧时代的格式化字符串 1.1.1. Option #1: %-formatting 1.1.2. 怎样使用 %-forma ...
- linux syscall 详解【转】
转自:https://blog.csdn.net/feixin620/article/details/78416560 引言:分析Android源码的过程中,要想从上至下完全明白一行代码,往往涉及ap ...
- Delphi 三层框架 DataSnap 的服务器端设置
elphi 三层框架 DataSnap 的服务器端设置: DataSnap 框架有三个模块:DataSnap Server,Server Module,DataSnap Client Module. ...
- python的wrapt模块实现装饰器
wrapt是一个功能非常完善的包,用于实现各种你想到或者你没想到的装饰器.使用wrapt实现的装饰器你不需要担心之前inspect中遇到的所有问题,因为它都帮你处理了,甚至inspect.getsou ...
- vue之登录和token处理
应用场景一 Vue刷新token,判断token是否过期.失效,进行登录判断跟token值存储 刷新token和token是否过期的操作都是由后端实现,前端只负责根据code的不同状态来做不同的操作: ...
- U盘被写保护不能重新格式化
今天一个朋友拿给我一个U盘,说这个U盘是商家送的,他想格式化,但是U盘被写保护了,系统不能格式化. 他想把这个U盘插到车子里听音乐,但是车载系统始终识别的是第一个分区,而这个分区正是被写保护那个,且这 ...