zoukankan      html  css  js  c++  java
  • poj 3080 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

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 using namespace std;
     6 const int maxn=65;
     7 char str[11][maxn];
     8 char temp[maxn];
     9 char ans[maxn];
    10 int main()
    11 {
    12     int t,n;
    13     int len;
    14     cin>>t;
    15     while(t--)
    16     {
    17         memset(ans,0,sizeof(ans));
    18         cin>>n;
    19         for(int i=1; i<=n; i++)
    20             cin>>str[i];
    21         for(int i=1; i<=60; i++)
    22         {
    23             bool flag=false;
    24             for(int j=0; j<=60-i; j++)
    25             {
    26                 len=0;
    27                 bool check=false;
    28                 for(int k=j; ; k++)
    29                 {
    30                     temp[len++]=str[1][k];
    31                     if(len==i)
    32                         break;
    33                 }
    34                 temp[len]='';
    35                 for(int k=2; k<=n; k++)
    36                 {
    37                     if(!strstr(str[k],temp))
    38                     {
    39                         check=true;
    40                         break;
    41                     }
    42                 }
    43                 if(!check)
    44                 {
    45                     flag=true;
    46                     if(strlen(ans)<strlen(temp))
    47                         strcpy(ans,temp);
    48                     else if(strcmp(ans,temp)>0)
    49                         strcpy(ans,temp);
    50                 }
    51             }
    52             if(!flag)
    53                 break;
    54         }
    55         if(strlen(ans)>=3)
    56             cout<<ans<<endl;
    57         else
    58             cout<<"no significant commonalities"<<endl;
    59     }
    60     return 0;
    61 }
    View Code
  • 相关阅读:
    mui 点击输入框软键盘弹起解决
    Vue中form表单常用rules校验规则
    ios new Date('yyyy-MM-dd HH-mm-ss').getTime() 方法获取不到时间戳
    uni-app运行到手机报错 Component constructors should be called while initialization. A constructor call has been ignored.
    vue-element-admin后台 点击侧边栏 刷新当前路由
    vue 防抖和节流
    vue data数据变化 页面数据不更新问题
    uni-app中页面部分内容使用索引列表(uni-indexed-list),动态数据
    css 文本单行显示溢出时出现省略号 多行显示溢出时出现省略号 首行缩进
    css实现两个div并排等高(一个div高度随另一个高度变化而变化)
  • 原文地址:https://www.cnblogs.com/cxbky/p/4926032.html
Copyright © 2011-2022 走看看