zoukankan      html  css  js  c++  java
  • ACM Data Structure Blue Jeans

     

    A - Blue Jeans

    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

    Submit Status

    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
    
    暴力搜索
     
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #define LEN 60
    using namespace std;
    
    int main()
    {
        int i,j;
        int test;
        scanf("%d",&test);
        for(int t = 1; t<=test;t++)
        {
            int n;
            scanf("%d",&n);
            char DNA[10][LEN+1];
            for(int p=0;p<n;p++)
            {
                scanf("%s",&DNA[p]);
            }
    //        for(int p=0;p<n;p++)
    //        {
    //            printf("%s
    ",DNA[p]);
    //        }
    
            char obj[LEN +1];
            int Strlen =0 ;
            int length = 1;
    
            for(int i=0;;i++)
            {
                char dna[LEN+1];
                int pi = i;
                if(pi+length >LEN)
                {
                    length ++;
                    i = -1;
                    if(length >LEN)
                        break;
                    continue;
                }
                for(j=0;j<length;j++)
                    dna[j]= DNA[0][pi++];
                dna[j] = '';
    
                bool flag = true;
                for(int k = 1;k<n;k++)
                {
                    if(!strstr(DNA[k],dna))
                    {
                        flag =false;
                        break;
                    }
                }
    
                if(flag)
                {
                    if(Strlen<length)
                    {
                        Strlen = length;
                        strcpy(obj,dna);
    
                    }
                    else if(Strlen == length)
                    {
                        if(strcmp(obj,dna) > 0)
                        {
                            strcpy(obj,dna);
                        }
                    }
                }
            }
    
            if(Strlen <3)
                puts("no significant commonalities");
            else
                printf("%s
    ",obj);
    
    
        }
        return 0;
    }
    
  • 相关阅读:
    C#事件(event)解析
    dll加入到GAC后,如何方便的调试
    『C程序设计』读书笔记系列文章之第四章 逻辑运算和判断选取控制
    C#委托之个人理解
    虚方法(virtual)和抽象方法(abstract)的区别
    『C程序设计』读书笔记系列文章之第二章 数据类型、运算符与表达式
    SOA概览(转)
    今天学的几个有用的句型
    【老孙随笔】PPT高手的启示
    【项目经理之修炼(11)】《初级篇》什么样的项目经理才可能成功??
  • 原文地址:https://www.cnblogs.com/wejex/p/3247757.html
Copyright © 2011-2022 走看看