Poj 3080 Blue Jeans, poj3080bluejeans

Source: Internet
Author: User

Poj 3080 Blue Jeans, poj3080bluejeans

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



The test data on POJ3080 is correct, but it is WA at the time of submission. Why? Which of the following can you tell me?

# Include <iostream>
# Include <string>
Using namespace std;
String a [11];
Int n;
Void bijiao ()
{
Int t = 1, slen = 0, result [11], qsz;
String ans = "";
For (int len = 60; len> = 3; len --)
{
For (qsz = 0; qsz <= 60-len; qsz ++)
{
T = 1;
A [10] = a [0]. substr (qsz, len );
For (int I = 1; I <n; I ++)
{
For (int qs = 0; qs <= 60-len; qs ++)
{
Result [I] = a [I]. compare (qs, len, a [10]);
If (result [I] = 0)
{
T ++; break;
}

// If (qs = 60-len)
// Goto loop;
}
If (t = n)
{
Slen = len;
Break;
}
}
If (t = n)
{
Slen = len;
If (ans = "" | ans> a [10]) ans = a [10];
Continue;
}
}
If (slen)
{
Break;
}
}
If (slen> = 3)
Cout <ans <endl;
Else
Cout <"no significant commonalities" <endl;
}
Int main ()
{
Int num;
Cin> num;
While (num --)
{
Cin> n;
For (int I = 0; I <n; I ++)
{
Cin> a [I];
}
Bijiao ();
}
Return 0;
}

POJ 3080 questions

# Include <iostream>
# Include <stdio. h>
# Include <string. h>
# Include <algorithm>
Using namespace std;
Struct STR {
Char data [62];
Int length;
};

STR str [11];

Int searchMaxSubString (int n)
{
Char subString [62], minLengthString [62];
Int OK = 0;
Char tempsubString [62]; // a temporary string is required
Int sublength, I, j;
Strcpy (minLengthString, str [0]. data );
Sublength = 60;
While (sublength> = 3) // If the length is 3
{
For (I = 0; I + sublength <61; I ++)
{
Strncpy (subString, minLengthString + I, sublength );
SubString [sublength] = '\ 0 ';
For (j = 1; j <n; j ++)
{
If (strstr (str [j]. data, subString) = NULL)
Break;
}
If (j = n)
{
// Printf ("% s \ n", subString );
If (! OK | strcmp (subString, tempsubString) <0) // if no or less than previously found
Strcpy (tempsubString, subString); // record the New String
OK = 1; // tag found
}
}
If (OK) // if found
{
Printf ("% s \ n", tempsubString); // output
Return 0;
}
Sublength --;
}
Printf ("no significant commonalities \ n ");
Return 0;
}
Int main ()
{
Int times, I, n;
Scanf ("% d", & times );
While (times --)
{
Scanf ("% d", & n );
For (I = 0; I <n; I ++)
{
Scanf ("% s", & str [I]. data );
}
SearchMaxSubString (n );
}
Return 0;
}... Remaining full text>

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.