POJ 2250 Compromise

Source: Internet
Author: User

Compromise
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 6654 Accepted: 2976 Special Judge

Description

In a few months the European Currency Union would become a reality. However, to join the club, the Maastricht criteria must being fulfilled, and this is not a trivial task for the countries (MA Ybe except for Luxembourg). To enforce that Germany would fulfill the criteria, our government have so many wonderful options (raise taxes, sell stocks, Revalue the Gold reserves,...) That's it's really hard to choose.

Therefore The German government requires a program for the following task:
Both politicians each enter their proposal of "what". The computer then outputs the longest common subsequence of words, the occurs in both proposals. As you can see, this is a totally fair compromise (after all, a common sequence of words is something what both people hav E in mind).

Your Country needs This program, so Your job was to write it for us.

Input

The input would contain several test cases.
Each test case consists of texts. Each text was given as a sequence of lower-case words, separated by whitespace, and with no punctuation. Words'll is less than and characters long. Both texts would contain less than words and would be terminated by a line containing a single ' # '.
Input is terminated by end of file.

Output

For each test case, print the longest common subsequence of words occuring in the. If there is more than one such sequence, all one is acceptable. Separate the words by one blank. After the last word, output a newline character.

Sample Input

Die Einkommen der Landwirtesind fuer die abgeordneten ein Buch mit sieben siegelnum dem Abzuhelfenmuessen dringend alle su Bventionsgesetze verbessert werden#die Steuern auf Vermoegen und einkommensollten nach Meinung der Abgeordnetennachdrueck Lich Erhoben Werdendazu muessen die Kontrollbefugnisse der finanzbehoerdendringend Verbessert werden#

Sample Output

Die Einkommen der Abgeordneten Muessen dringend verbessert werden

Test instructions: Give two paragraphs to find the longest common word string
Idea: LCS problem, only need to open a two-dimensional record to be good

1#include <stdio.h>2#include <string.h>3#include <algorithm>4 using namespacestd;5 6 Chara[ *][ the],b[ *][ the],c[ *][ the];7 intdp[ the][ the],mark[ the][ the],len1,len2,cnt;8 9 voidLCS ()Ten { One     inti,j; AMemset (DP,0,sizeof(DP)); -memset (Mark,0,sizeof(Mark)); -      for(i =0; i<=len1;i++) themark[i][0] =1; -      for(i =0; i<=len2;i++) -mark[0][i] =-1; -      for(i =1; i<=len1; i++) +     { -          for(j =1; j<=len2; J + +) +         { A             if(!STRCMP (a[i-1],b[j-1])) at             { -DP[I][J] = dp[i-1][j-1]+1; -MARK[I][J] =0; -             } -             Else if(dp[i-1][j]>=dp[i][j-1]) -             { inDP[I][J] = dp[i-1][j]; -MARK[I][J] =1; to             } +             Else -             { theDP[I][J] = dp[i][j-1]; *MARK[I][J] =-1; $             }Panax Notoginseng         } -     } the } +  A voidPrintlcs (intIintj) the { +     if(!i&&!j) -         return ; $     if(mark[i][j]==0) $     { -Printlcs (I-1, J-1); -strcpy (c[cnt++],a[i-1]); the     } -     Else if(mark[i][j]==1)Wuyi     { thePrintlcs (I-1, j); -     } Wu     Else -     { AboutPrintlcs (i,j-1); $     } - } -  - intMain () A { +     inti; the      while(~SCANF ("%s", a[0])) -     { $Len1 =1; the          while(strcmp (a[len1-1],"#")) thescanf"%s", a[len1++]); thelen1-=1; thescanf"%s", b[0]); -Len2 =1; in          while(strcmp (b[len2-1],"#")) thescanf"%s", b[len2++]); the LCS (); AboutCNT =0; the Printlcs (len1,len2); theprintf"%s", c[0]); the          for(i =1; i<cnt; i++) +         { -printf"%s", C[i]); the         }Bayiprintf"\ n"); the     } the  -  -     return 0; the}

POJ 2250 Compromise

Related Keywords:

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.