Links: Poj 3080
Test Instructions : Enter n DNA sequences, each of which has a DNA sequence length of 60.
Find the longest co-owned subsequence of these strings.
Note : if not found. or the oldest sequence length is less than 2, the output is no significant commonalities, otherwise the longest common substring is output. if the length of the same output dictionary order of the smallest
ideas : Violent enumeration of each subsequence of the first DNA sequence, matched with the rest of the sequence with the STRSTR () function
Strstr (s,t) is to find the T string in the s string, and if found, returns the address of the first character in S where the T-string appears. If not found, returns null
#include <stdio.h> #include <string.h>char t[65],ans[65];void cmp () {if (strlen (ans) <strlen (t)) STRCP Y (ans,t); else if (strlen (ans) ==strlen (t)) if (strcmp (ans,t) >0) strcpy (ans,t);} int main () {int n,m,i,j,k,a; Char s[12][65]; scanf ("%d", &n); while (n--) {scanf ("%d", &m); for (i=0;i<m;i++) scanf ("%s", S[i]); ans[0]=0; for (i=0;i<60;i++) {//substring starting from position I k=0; for (j=i;j<60;j++) {t[k++]=s[0][j]; Add a character t[k]=0 each time after the previous substring; Remember to add the empty character for (a=1;a<m;a++) at the end of the substring//to infer if the remaining string includes the substring if (strstr (s[a],t) ==n ULL) break; if (A==M) CMP (); }} if (strlen (ans) >=3) printf ("%s\n", ans); else printf ("no significant commonalities\n"); } return 0;}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
POJ 3080 Blue Jeans