Blue Jeans(串)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 10083 | Accepted: 4262 |
Description
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
- 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
Sample Input
3
2
GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
3
GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA
GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
3
CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
Sample Output
no significant commonalities
AGATAC
CATCATCAT 题意:寻找m个序列中共有的最长的子串,长度小于3的输出no significant commonalities,长度相等时输出字典序小的;
解题思路:枚举第一个序列的所有子串,每枚举出一个检查该子串是否是m个序列共有的,若是,比较该串与ans[]的长度取较长的,若长度相等取字典序小的;当枚举完所有子串后,ans[]保存的就是m个序列共有的最长的串。
#include<stdio.h>
#include<string.h> int main()
{
int i,j,k,n,t;
char DNA[][],tmp[],ans[];
scanf("%d",&t);
while(t--)
{
ans[] = '\0';
scanf("%d",&n);
for(i = ; i < n; i++)
scanf("%s",DNA[i]);
for(i = ; i < ; i++)//枚举子串的起点
{
for(j = i+; j < ; j++)//枚举子串的终点
{
int cnt = ;
for(k = i; k <= j; k++)
{
tmp[cnt++] = DNA[][k];
}
tmp[cnt] = '\0';//得到一个子串
for(k = ; k < n; k++)
{
if(strstr(DNA[k],tmp) == NULL)
break;
}
if(k < n) continue;
if(strlen(ans) == strlen(tmp))
{
if(strcmp(ans,tmp) > )
strcpy(ans,tmp);
}
else
{
if(strlen(tmp) > strlen(ans))
strcpy(ans,tmp);
}
}
}
if(strlen(ans) < ) printf("no significant commonalities\n");
else printf("%s\n",ans);
}
return ;
}
Blue Jeans(串)的更多相关文章
- POJ 3080 Blue Jeans(串)
题目网址:http://poj.org/problem?id=3080 思路: 以第一个DNA序列s为参考序列,开始做以下的操作. 1.将一个字母s[i]作为匹配串.(i为当前遍历到的下标) 2.遍历 ...
- POJ 3080 Blue Jeans(Java暴力)
Blue Jeans [题目链接]Blue Jeans [题目类型]Java暴力 &题意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 规定: 1. 最长公共 ...
- poj3080 Blue Jeans【KMP】【暴力】
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions:21746 Accepted: 9653 Descri ...
- (字符串 KMP)Blue Jeans -- POJ -- 3080:
链接: http://poj.org/problem?id=3080 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88230#probl ...
- POJ 3080 Blue Jeans 找最长公共子串(暴力模拟+KMP匹配)
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20966 Accepted: 9279 Descr ...
- POJ Blue Jeans [枚举+KMP]
传送门 F - Blue Jeans Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- POJ 3080 Blue Jeans (求最长公共字符串)
POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...
- poj 3080 Blue Jeans
点击打开链接 Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10243 Accepted: 434 ...
- POJ3080——Blue Jeans(暴力+字符串匹配)
Blue Jeans DescriptionThe Genographic Project is a research partnership between IBM and The National ...
随机推荐
- app 的内存优化
这篇文章是笔者在开发App过程中发现的一些内存问题, 然后学习了YYKit框架时候也发现了图片的缓存处理 (YYKit 作者联系了我, 说明了YYKit重写imageNamed:的目的不是为了内存管理 ...
- Android 6.0 Changes
原文链接:http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html 伴随着新特性和功能,Andr ...
- shell脚本实现冒泡排序 分类: 学习笔记 linux ubuntu 2015-07-10 14:16 79人阅读 评论(0) 收藏
手动输入一行字符串,并对其排序. 脚本如下: #!/bin/bash #a test about sort echo "please input a number list" re ...
- C语言循环的嵌套
注:参考网络资源拟制,如雷同请见谅循环的嵌套:一个循环体语句中又包含另一个循环语句,称为循环嵌套.嵌套注意事项:1.使用循环嵌套时,内层循环和外层循环的循环控制变量不能相同.2.循环嵌套结构的书写,最 ...
- springmvc配置文件 spring-servlet
<?xml version="1.0" encoding="UTF-8"?><!-- Bean头部 --><beans xmlns ...
- .net 学习路线感想
从上到大学到现在工作,已经有六年多了,发现学习编程到以开发为工作也是一个挺长的过程的. 大学中,从c语言到java.C#到其他各种语言的学习,还有其他知识的学习如:数据库(oracle.sql Ser ...
- Android开发常见错误类型一览表
这是我的第一个博客,我会一直添加我在Android开发中遇到的错误,用来记录我开发中踩过的那些坑 ------------------------分割线------------------------ ...
- 惠普 Compaq 6520s 无线开关打不开
问题描述:键盘上面的无线开关怎么按都打不开,始终是出于黄色的状态 解决方法:尝试恢复bios默认值测试: 开机不停点击F10进入bios,选择File选项,选择Restore Defaults-- ...
- 十五、C# 使用查询表达式的LINQ
使用查询表达式的LINQ 本章介绍了一种新的语法,查询表达式. 1.查询表达式概述 2.特点:投射 筛选 排序 Let 分组 3.作为方法调用 标准查询运算符所实现的查询在功能上 ...
- php && 逻辑与运算符使用说明
例子:!defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc()); o(︶︿︶ ...