码迷,mamicode.com
首页 > 其他好文 > 详细

poj 3080 Blue Jeans 暴力

时间:2015-08-17 14:05:11      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:字符串匹配   暴搜   

Blue Jeans
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 14283   Accepted: 6356

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

题意: 求出多组字符串的最大相邻公共子串,若长度小于三则输出“no significant commonalities”,否则,对于输出公共子串,对于同样长度的公共子串,输出按字母排序较小的串

思路:暴搜暴搜暴搜~~~

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
char a[15][65];
char anss[65];
int main(){
    int n;
    scanf("%d",&n);
    while(n--){
        int m;
        scanf("%d",&m);
        int i,j,k;
        for(i=0;i<m;i++){
            scanf("%s",a[i]);
        }
        int ans=0;
        int len=strlen(a[0]);
        char sub[65];
        for(i=0;i<len;i++){
            for(j=i+2;j<len;j++){
                strncpy(sub,a[0]+i,j-i+1);
            sub[j-i+1]='\0';
            int flag=1;
            for(k=1;flag&&k<m;k++){
                if(strstr(a[k],sub)==0){
                    flag=0;
                }
            }
            if(flag&&(ans<strlen(sub)||(ans==strlen(sub)&&strcmp(anss,sub)>=0))){//记得比较一下
                ans=strlen(sub);
                strcpy(anss,sub);
            }
        }
        }
        if(ans<3) printf("no significant commonalities");
        else
        printf("%s",anss);
        printf("\n");
    }
}




版权声明:本文为博主原创文章,未经博主允许不得转载。

poj 3080 Blue Jeans 暴力

标签:字符串匹配   暴搜   

原文地址:http://blog.csdn.net/taluoyaxin/article/details/47723779

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!