九度oj 1042
来源:互联网 发布:html 作为java gui 编辑:程序博客网 时间:2024/05/17 07:36
- 题目描述:
Find a longest common subsequence of two strings.
- 输入:
First and second line of each input case contain two strings of lowercase character a…z. There are no spaces before, inside or after the strings. Lengths of strings do not exceed 100.
- 输出:
For each case, output k – the length of a longest common subsequence in one line.
- 样例输入:
abcdcxbydz
- 样例输出:
2
- 来源:
- 2008年上海交通大学计算机研究生机试真题
#include<iostream>#include<string.h>#include<stdio.h>using namespace std;int a[101][101];int max(int x,int y){ return (x>y)?x:y;}int main(){ char s1[101],s2[101]; while(cin>>s1>>s2) { int l1=strlen(s1); int l2=strlen(s2); for(int i=0;i<=l1;i++) { a[i][0]=0; } for(int j=0;j<=l2;j++) { a[0][j]=0; } for(int i=1;i<=l1;i++) { for(int j=1;j<=l2;j++) { if(s1[i-1]!=s2[j-1]) { a[i][j]=max(a[i][j-1],a[i-1][j]); } else a[i][j]=a[i-1][j-1]+1; } } cout<<a[l1][l2]<<endl; } }
0 0
- 九度oj 1042
- 九度OJ 1042
- 九度oj-1042-Coincidence
- [九度OJ]1042Coincidence
- 【九度OJ】:九度OJ 1050
- 【九度OJ】:九度OJ 1053
- 【九度OJ】:九度OJ 1056
- 【九度OJ】:九度OJ 1059
- 【九度OJ】:九度OJ 1206
- 九度oj 题目1042:Coincidence
- 九度OJ:1000
- 【九度OJ】 1006
- 九度 OJ 1499
- 九度OJ-1002
- 九度OJ-1003
- 九度OJ 1004
- 九度OJ 1003
- 九度oj 采药
- 达内学习日志Day04(再续):数列求和
- 为什么不应该重写service方法?
- 反射与注解
- REST 风格的 Web 服务入门指南和 (重要)REST关键原则
- 【Java多线程】之七:死锁例子
- 九度oj 1042
- leetcode 88: Merge Sorted Array
- ccs工程文件类型和作用
- HTML5的数据缓存
- Longest Common Prefix
- 【错误笔记】GDB调试
- UITextField
- ac数量破100了。欧耶!!!
- POJ_1321_棋盘问题