Poj 3080 Blue Jeans

Source: Internet
Author: User

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 ;}


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.