/* 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]