poj 3080 Blue Jeans

Blue Jeans
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 16354 Accepted: 7260

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

Source

提示

题意:

基因工程项目与IBM和美国国家地理杂志社会是研究伙伴关系,分析成千上万的DNA。

作为IBM的研究员,你的任务就是写一个程序,找到给定DNA片段的共同点使其可以与个人信息相关调查以确定新的遗传标记。有四个碱基:腺嘌呤(A)、胸腺嘧啶(T),鸟嘌呤(G)、胞嘧啶(C)。例如:6个碱基的DNA序列可以表示为TAGACC。

给定一组DNA碱基序列,确定在所有序列中的最长碱基序列。(最长公共子串)

最长子串不少于3个字符,有一样长的话输出字典序最小的,没有就输出no significant commonalities。

思路:

去暴力吧,还是0ms(⊙o⊙)哦。(附上测试样例)

示例程序

Source Code

Problem: 3080		Code Length: 1828B
Memory: 388K		Time: 0MS
Language: GCC		Result: Accepted
#include <stdio.h>
#include <string.h>
int n,m,i,i1,i2,i3,i4,l;
char ch[10][61],a[61],b[61];		//a[61]作为最长子串的中转点,因为如果一样长还需要比较字典序,b[61]才是最终答案
int main()
{
    scanf("%d",&n);
    for(i=1;n>=i;i++)
    {
        b[0]='#';			//对是否有子串的字符数组初始化
        scanf("%d",&m);
        for(i1=0;m>i1;i1++)
        {
            scanf("%s",ch[i1]);
        }
        for(i1=60;i1>=3;i1--)			//字串长度,从大到小
        {
            for(i2=0;60-i1>=i2;i2++)			//同等长度不一样的子串
            {
                for(i3=1;m>i3;i3++)				//开始比较,以第一个字符串为基准
                {
                    l=0;
                    for(i4=0;60>i4;i4++)				//寻找其他字符串是否存在这个字串
                    {
                        if(ch[0][i2+l]==ch[i3][i4])
                        {
                            l++;
                        }
                        else
                        {
                            l=0;
                            if(ch[0][i2+l]==ch[i3][i4])
                            {
                                l++;
                            }
                        }
                        if(l==i1)			//有就跳出
                        {
                            break;
                        }
                    }
                    if(i4==60)			//没有说明这个字串不是
                    {
                        break;
                    }
                }
                if(i4!=60)		//i4没到60说明存在,并且有一样长的就比较
                {
                    for(l=0;i1>l;l++)
                    {
                        a[l]=ch[0][i2+l];
                    }
                    a[l]='\0';
                    if(b[0]=='#'||strcmp(b,a)>0)
                    {
                        strcpy(b,a);
                    }
                }
            }
            if(b[0]!='#')		//已找到答案
            {
                break;
            }
        }
        if(b[0]!='#')
        {
            printf("%s",b);
        }
        else
        {
            printf("no significant commonalities");
        }
        printf("\n");
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值