UVA 10100Longest Match

Source: Internet
Author: User

Longest Match

A newly opened detective agency is struggling with their limited intelligence to find out a secret

Information passing technique among its detectives. Since They is new in this profession, they know

Well that their messages would easily be trapped and hence modified by other groups. They want to guess

The intensions of other groups by checking the changed sections of messages. First they has the to get the

Length of longest match. You is going to the help them.

Input

The input Le may contain multiple test cases. Each case would contain the successive lines of string.

Blank lines and Non-letter printable punctuation characters may appear. Each line of string would be

No longer than characters. Length of each word would be is less than characters.

Output

For each case of input, you have to output a line starting with the case number right justified in a field

Width of, followed by the longest match as shown in the sample output. In case of at least one blank

Line for each input output '

blank!

Consider the Non-letter punctuation characters as white-spaces.

Sampleinput

This is a test.

Test

Hello!

The document provides late-breaking information

Late breaking.

Sampleoutput

1. Length of Longest match:1

2. blank!

3. Length of Longest match:2

The problem is the longest common sub-sequence of deformation.

Recursive formula for the longest common subsequence:

Dp[i+1][j+1] = {

Max (dp[i][j]+1, d[i][j+1], D[i+1][j]) (si+1 = tj+1)

Max (d[i][j+1], d[i+1][j]) other

}

#include <cstdio>#include<iostream>#include<cstring>#include<cstring>#include<cctype>using namespacestd;Const intMAXN =1003;stringTEXT[MAXN], PATTERN[MAXN];intDP[MAXN][MAXN];BOOLIsTrueCharc) {    if(c >='a'&& C <='Z')|| (c >='A'&& C <='Z') || (c >='0'&& C <='9')){        return true; }    return false;}voidDevide (stringStr[],stringSint&ans) {ans=0; str[0].clear ();  for(inti =0; I < s.size (); i++){        if(IsTrue (S[i])) {Str[ans]+=S[i]; }Else {            if(Str[ans].empty ()) {Continue; } ans++;        Str[ans].clear (); }    }    if(IsTrue (S[s.size ()-1])) ans++;}intMain () {stringstr1, str2; intnum =0, NUM1, num2;;  while(!cin.eof ())        {getline (cin, STR1);        Getline (CIN, STR2); printf ("%2d.", ++num); if(Str1.empty () | |Str2.empty ()) {cout<<"blank!"<<Endl; }Else{devide (text, str1, NUM1);            Devide (Pattern, str2, num2); Memset (DP,0,sizeof(DP));  for(inti =0; i < NUM1; i++){                 for(intj =0; J < num2; J + +){                    if(Text[i] = =Pattern[j]) {Dp[i+1][j+1] = Dp[i][j] +1; }Else{dp[i+1][j+1] = max (dp[i+1][J], dp[i][j+1]); } }} cout<<"Length of longest match:"&LT;&LT;DP[NUM1][NUM2] <<Endl; }    }    return 0;}
View Code

UVA 10100Longest Match

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.