Link: poj 3080
Enter n DNA sequences, each of which has a length of 60. Find the longest co-occurrence subsequence of these strings.
NOTE: If no value is found, or the length of the oldest sequence is less than 2, no significant commonalities is output. Otherwise, the longest common substring is output. If the length is the same, the smallest Lexicographic Order is output.
Idea: enumerate each sub-sequence of the first DNA sequence in brute force mode, and use the strstr () function to match other sequences.
Strstr (S, T) is to find the T string in the S string. If it is found, return the first character of the T string in S. If it is not found, return null
# Include <stdio. h> # include <string. h> char T [65], ANS [65]; void CMP () {If (strlen (ANS) <strlen (t) strcpy (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 ++) {// the starting position of the substring is I k = 0; for (j = I; j <60; j ++) {T [k ++] = s [0] [J]; // Add a character T [k] = 0 after the previous substring each time; // remember to add an empty character for (a = 1; A <m; A ++) // determine whether other strings contain the substring if (strstr (s [a], t) = NULL) break; if (a = m) CMP () ;}} if (strlen (ANS) >=3) printf ("% s \ n", ANS ); else printf ("no significant commonalities \ n");} return 0 ;}