POJ 3080 Blue Jeans (KMP)

Source: Internet
Author: User

http://poj.org/problem?id=3080

Blue Jeans

Description

The Genographic Project is a-partnership between IBM and the National Geographic Society that's analyzing DNA fr Om Hundreds of thousands of contributors to map how the Earth was populated.

As an IBM researcher, you had been tasked with writing a program that would find commonalities amongst given snippets of D NA that can is 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 was found in the molecule. There is 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 would begin with a line containing a single integer n indicating the number of datasets. Each dataset consists of the following components:
    • A single Positive An integer m (2 <= m <=) indicating the number of the base sequences in this DataSet.
    • M lines each containing a single base sequence consisting of 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" in Stead. If multiple subsequences of the same longest length exist, output only the subsequence that comes first in alphabetical or Der.

Sample Input

32GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA A3gataccagataccagataccagataccagataccagataccagataccagataccagatagatactagatactagatactagatactaaaggaaagggaaaaggggaaaaagggggaaa Agataccagataccagataccagataccaaaggaaagggaaaaggggaaaaagggggaaaa3catcatcatcccccccccccccccccccccccccccccccccccccccccccccccccc Cacatcatcataaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacatcatcatttttttttttttttttttttttttttttttttttttttttttttttttt

Sample Output

No significant commonalitiesagataccatcatcat
#pragma COMMENT (linker, "/stack:102400000,102400000") #include <iostream> #include <queue> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <cstdlib># Include <limits> #include <stack> #include <vector> #include <map>using namespace std; #define N 100#define INF 0xfffffff#define PI acos ( -1.0) #define EPS 1e-8#define met (A, b) memset (A, B, sizeof (a)) Char Str[n][n];in    T N;bool Judge (char sub[]); int main () {int t;    scanf ("%d", &t);        while (t--) {scanf ("%d", &n);        for (int i=0; i<n; i++) scanf ("%s", Str[i]);        int flag = 0;        Char S1[n], s[n], sub[n];        int len = strlen (S1), len1 = 0;        Met (S, 0);        strcpy (S1, str[0]); for (int. I=len; i>=1; i--) {for (int j=0; j<=len-i; J + +) {Met (sub, 0)                ;                strncpy (Sub, s1+j, i);   if (Judge (sub))             {if (!flag) {strcpy (S, sub);                        Len1 = strlen (s);                    flag = 1;                } else if (strlen (sub) = = Len1 && strcmp (S, sub)) strcpy (S, sub);        }}} if (Len1 < 3) puts ("no significant commonalities");    else puts (s); } return 0;}    BOOL Judge (char sub[]) {for (int i=1; i<n; i++) if (Strstr (Str[i], sub) = = NULL) return false; return true;} /*32asdfgsdfgh*/


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 3080 Blue Jeans (KMP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.