Poj 1580 String Matching

Source: Internet
Author: User
// Note: you must understand the meaning of the question: instead of finding the same character from the two strings, you can find it in the process of comparing strings one by one! # Include <iostream> # include <string> # include <algorithm> using namespace STD; int gcd (int A, int B) {while (B %) {int T = A; A = B % A; B = T;} return a;} int main () {int I, J, K, len1, len2, common, slen, Max; string str1, str2, TMP; while (CIN> str1) {If (str1 = "-1") break; common = 0; CIN> str2; TMP = str2; len1 = str1.length (); len2 = str2.length (); for (I = 0; I <len1; ++ I) {for (j = 0; j <len2; ++ J) {max = 0; For (INT I1 = I, J1 = J; I1 <len1 & J1 <len2; ++ I1, ++ J1) if (str1 [I1] = str2 [J1]) + + Max; If (common <max) Common = max ;}} slen = len1 + len2; if (Common = 0) cout <"appx (" <str1 <"," <TMP <") =" <0 <Endl; else {int num = gcd (Common * 2, slen); If (slen = Common * 2) cout <"appx (" <str1 <", "<TMP <") = "<1 <Endl; else cout <" appx ("<str1 <", "<TMP <") = "<Common * 2/num <"/"<slen/num <Endl ;}} system (" pause ");} /* car cartturkey chickenmoney povertyrough peskya ameet eathappy play-1 */

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.