Poj 1580 string matching [string processing]

Source: Internet
Author: User
Tags first string
/* Question: When a mobile string matches another string, the rule that finds the maximum number of matches is to fix one string, then compare the string with another string from left to right */
# Include <stdio. h> # include <string. h >#define M 10000 char a [m], B [m]; int gcd (int A, int B) {If (B = 0) return; else return gcd (B, A % B);} int main () {While (scanf ("% s", )! = EOF) {If (strcmp ("-1", a) = 0) break; scanf ("% s", B); int LA = strlen (); int lB = strlen (B); int max = 0; For (INT I = 0; I <la; I ++) {// fix the second string, then move the first string int temp = 0; For (Int J = 0, K = I; j <LB & K <la; j ++, K ++) {if (a [k] = B [J]) {++ temp ;}} if (max <temp) max = temp ;}for (INT I = 0; I <Lb; I ++) {<span style = "font-family: Arial, Helvetica, sans-serif;"> // fix the first string, then move the second string </span> int temp = 0; For (Int J = 0, K = I; j <la & K <Lb; j ++, k ++) {if (a [J] = B [k]) {++ temp ;}} if (max <temp) max = temp ;} // printf ("% d \ n", max); Max * = 2; printf ("appx (% s, % S) =", a, B ); if (max = 0) {printf ("0 \ n"); continue;} If (max = La + lB) {printf ("1 \ n "); continue;} int temp = gcd (La + lB, max); // printf ("% d \ n", temp ); printf ("% d/% d \ n", max/temp, (La + lB)/temp );}}
Question link http://poj.org/problem? Id = 1580

Poj 1580 string matching [string processing]

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.