In a few months the European Currency Union will become a reality. However, to join the club, the Maastricht criteria must be fulfilled, and this is not a trivial task for the countries (maybe except for Luxembourg). To enforce that Germany will fulfill the criteria, our government has so many wonderful options (raise taxes, sell stocks, revalue the gold reserves,...) that it is really hard to choose what to do.

Therefore the German government requires a program for the following task: 
Two politicians each enter their proposal of what to do. The computer then outputs the longest common subsequence of words that 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 have in mind).

Your country needs this program, so your job is to write it for us.

Input

The input will contain several test cases. 
Each test case consists of two texts. Each text is given as a sequence of lower-case words, separated by whitespace, but with no punctuation. Words will be less than 30 characters long. Both texts will contain less than 100 words and will 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 two texts. If there is more than one such sequence, any one is acceptable. Separate the words by one blank. After the last word, output a newline character.

Sample Input

die einkommen der landwirte
sind fuer die abgeordneten ein buch mit sieben siegeln
um dem abzuhelfen
muessen dringend alle subventionsgesetze verbessert werden
#
die steuern auf vermoegen und einkommen
sollten nach meinung der abgeordneten
nachdruecklich erhoben werden
dazu muessen die kontrollbefugnisse der finanzbehoerden
dringend verbessert werden
#

Sample Output

die einkommen der abgeordneten muessen dringend verbessert werden
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<map> using namespace std;
const int N = + ;
int dp[N][N], Mark[N][N];
char ch[];
string a[N], b[N];
void Work(int len_1, int len_2){
memset(Mark, , sizeof(Mark));
memset(dp, , sizeof(dp));
for(int i = ; i <= len_1; i++)
for(int j = ; j <= len_2; j++)
if(a[i] == b[j]){ dp[i][j] = dp[i-][j-] + ; Mark[i][j] = ;}
else if(dp[i-][j] >= dp[i][j-]) {dp[i][j] = dp[i-][j]; Mark[i][j] = ;}
else dp[i][j] = dp[i][j-],Mark[i][j] = ;
}
bool flag;
void Solve(int i, int j){
if(i == || j == ) return;
if(Mark[i][j] == ){
Solve(i-, j-);
if(flag) printf(" ");
flag = true;
printf("%s",a[i].c_str());
}else if(Mark[i][j] == ){
Solve(i-, j);
}else if(Mark[i][j] == )
Solve(i, j - );
}
int main(){
while(cin >> ch){
int len_1 = ,len_2 = ;
flag = false;
a[len_1++] = ch;
while(cin >> ch &&ch[] != '#'){
a[len_1++] = ch;
}
while(cin >> ch && ch[] != '#'){
b[len_2++] = ch;
}
Work(len_1, len_2);
Solve(len_1, len_2);
printf("\n");
}
}

最新文章

  1. Linux C--信号 sigaction函数
  2. 【转载】 wpf无边框的方法以及拖拽的问题
  3. linux命令集——&lt;一&gt;目录处理命令
  4. 【tarjan】BZOJ 1051:受欢迎的牛
  5. 【转】Android设计中的.9.png
  6. Dumpbin的使用方法
  7. nutch 很多url unfetched的原因
  8. SQL server 创建表,索引,主键,外键
  9. 【HDOJ】2425 Hiking Trip
  10. 怎么判断PC端浏览器内核
  11. jQuery插件 -- 图片随页面滚动fixed
  12. Object-C 里面的animation动画效果,核心动画
  13. (5)UIView常见属性
  14. Promise和setTimeout执行顺序 面试题
  15. iview 表单非空验证
  16. SVN和Git对比梳理
  17. select option 选中 取消js
  18. A1024. Palindromic Number
  19. Pandas时间序列
  20. django的admin后台注册model并显示

热门文章

  1. js判断条件为“假”的情况
  2. 模板引擎ejs
  3. BZOJ 3193: [JLOI2013]地形生成 计数 + 组合 + 动态规划
  4. 【BZOJ4565】 [Haoi2016]字符合并
  5. 【转】Python Schema一种优雅的数据验证方式
  6. ArrayList,Vector ,LinkedList的存储性能和特性
  7. 虚树总结&amp;题单&amp;简要题解
  8. MapReduce数据倾斜的解决方式
  9. Java之Integer类
  10. layui table指定某一行样式