Coincidence
来源:互联网 发布:linux 打开本地目录 编辑:程序博客网 时间:2024/06/05 08:14
Coincidence
题目描述:
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
code
#include<iostream>#include<string>using namespace std;//要比较的string str1, str2;//int max(int a, int b){ return a > b ? a : b;}int main(){ while (cin >> str1 >> str2) { //初始化 const int N = 101; int LCS[N][N]; //存储LCS int a = str1.length(); int b = str2.length(); //求解 for (int i = 0; i <= a; i++) { for (int j = 0; j <= b; j++) { if (i == 0) LCS[i][j] = 0; else if (j == 0) LCS[i][j] = 0; else if (str1[i-1] == str2[j-1]) LCS[i][j] = LCS[i - 1][j - 1] + 1; else LCS[i][j] = max(LCS[i - 1][j], LCS[i][j - 1]); } } cout << LCS[a][b] << endl; } return 0;}
0 0
- Coincidence
- Coincidence
- Coincidence
- OJ_1042 Coincidence
- All of coincidence
- 题目1042:Coincidence
- 题目1042:Coincidence
- 题目1042:Coincidence
- 九度1042:Coincidence
- 题目1042:Coincidence
- 九度[1042]-Coincidence
- 九度oj-1042-Coincidence
- [九度OJ]1042Coincidence
- Parajumpers Herren What a coincidence
- Jobdu1042 Coincidence(DP,LCS模板)
- Coincidence(LCS最长公共子序列)
- 九度oj 题目1042:Coincidence
- 题目1042:Coincidence(最长公共子序列)
- DB2 执行Sql 语句中时的with ur
- 烤鸭的gerrit使用总结
- Linux环境配置增强型的Oracle简单客户端-Instant_Client
- uva1350 Pinary(递推)
- contiki 启动进程 process_start
- Coincidence
- C++模板及模板特化
- svn配置到windows自启动服务中
- Android中图片资源适配
- LeetCode 19 Remove Nth Node From End of List 移除倒数第N个节点
- 网页设计
- fn标签的用法
- Git教程
- linux service 简单易懂贴