Blue Jeans
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 14283 |
|
Accepted: 6356 |
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
Test instructions: Find the largest contiguous common substring of multiple sets of strings, if the length is less than three output "no significant commonalities", otherwise, for the output of the common substring, for the same length of the common substring, the output alphabetical order of the smaller string
Thoughts: Mob Search
#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]= ' + '; 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))) {//Remember to compare Ans=strlen (sub); strcpy (anss,sub); }}} if (ans<3) printf ("no significant commonalities"); else printf ("%s", ANSS); printf ("\ n"); }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
POJ 3080 Blue Jeans violence