POJ 3080--blue Jeans "KMP && Brute Force enumeration"

Source: Internet
Author: User

Blue Jeans
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 14316 Accepted: 6374

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

#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;char str[15][100];int    Next[100];void GetNext (char *s1) {int J = 0, k =-1;    int len = strlen (S1);    Next[0] =-1;            while (J < Len) {if (k = =-1 | | s1[j] = = S1[k]) {++j;            ++k;        NEXT[J] = k;    } else K = next[k]; } return;    BOOL KMP (char *s1, char *s2) {int len1 = strlen (s2);    int len2 = strlen (S1);    GetNext (S1);    int i = 0, j = 0;            while (I < len1) {if (j = =-1 | | s1[j] = = S2[i]) {++i;        ++j;        } else j=next[j];    if (j = = Len2) return true; } return false;}    int main () {int T;    scanf ("%d", &t);    Char temp[100];    Char sum[100];        while (t--) {int n;        scanf ("%d", &n);        for (int i = 0; i < n; ++i) scanf ("%s", Str[i]);        int len = strlen (str[0]);        memset (sum, ' n ', sizeof (sum)); for (int i = 0; i < Len            ++i) {//The beginning of the enumeration string int ans = 0;                for (int j = i; j < Len; ++j) {//End of enumeration string temp[ans++] = str[0][j];//Store new string Temp[ans] = ' + ';                int flag = 1;  for (int k = 1; k < n; ++k) {//new string and str[] match if (!KMP (temp, str[k]) {//Match failed flag =                        0;                    Break }} if (flag) {///Match success//longest common substring and dictionary order minimum if (strlen (temp) &G T                    strlen (sum)) strcpy (sum, temp);                else if (strlen (temp) ==strlen (sum) && strcmp (temp, sum) < 0) strcpy (sum, temp);        }}} if (Strlen (SUM) < 3) printf ("no significant commonalities\n");    else printf ("%s\n", sum); } return 0;}


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

POJ 3080--blue Jeans "KMP && Brute Force enumeration"

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.