题目1042:Coincidence
来源:互联网 发布:淘宝对话生成器 编辑:程序博客网 时间:2024/06/06 03:26
- 题目描述:
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
C++代码:
#include<iostream>#include<string>using namespace std;int a[110][110];string s1,s2;int main(){ while(cin>>s1>>s2){ int m=s1.length(); int n=s2.length(); for(int i=0;i<m;i++) for(int j=0;j<n;j++){ a[i][j]=0; } for(int i=1;i<=m;i++) for(int j=1;j<=n;j++){ if(s1.at(i-1)==s2.at(j-1)){ a[i][j]=a[i-1][j-1]+1; }else{ if(a[i-1][j]>=a[i][j-1]){ a[i][j]=a[i-1][j]; }else{ a[i][j]=a[i][j-1]; } } } cout<<a[m][n]<<endl; } return 0;}
阅读全文
0 0
- 题目1042:Coincidence
- 题目1042:Coincidence
- 题目1042:Coincidence
- 题目1042:Coincidence
- 九度oj 题目1042:Coincidence
- 题目1042:Coincidence(最长公共子序列)
- 题目1042:Coincidence(2008年上海交通大学计算机研究生机试真题)
- 九度 oj 题目1042:Coincidence (LCS)
- 九度1042:Coincidence
- 九度[1042]-Coincidence
- Coincidence
- Coincidence
- Coincidence
- 九度oj-1042-Coincidence
- [九度OJ]1042Coincidence
- 九度OJ-1042:Coincidence(最长公共子序列)
- OJ_1042 Coincidence
- 九度OJ 1042 Coincidence -- 动态规划(最长公共子序列)
- Linux安装ArcGIS Server提示缺少gettext包,通过挂载光盘并安装包
- 文件拖拽上传
- 数组中重复次数最多的数字
- ViewPager无限轮播(真正的左右无限滑动)
- 图像处理之直方图均值化
- 题目1042:Coincidence
- 计算机网络之面试常考
- 面试心得体会
- 覆盖equals时请遵守通用约定
- tomcat运行时报 cannot be cast to javax.servlet.Servlet
- jdk-8u131wiindows64位版本安装时错误1335的解决办法
- set_irq_type函数解析
- 算法2.7堆排序(algs)
- css书写规范