当前位置:网站首页>C - Common Subsequence
C - Common Subsequence
2022-06-26 13:08:00 【YJEthan】
Description
The program input is from a text file. Each data set in the file contains two strings representing the given sequences. The sequences are separated by any number of white spaces. The input data are correct. For each set of data the program prints on the standard output the length of the maximum-length common subsequence from the beginning of a separate line.
Input
Output
Sample Input
abcfbc abfcab
programming contest
abcd mnp
Sample Output
4
2
0
#include<stdio.h>
#include<string.h>
int Max(int a,int b)
{
if(a>b) b=a;
return b;
}
int maxlen[10001][10001];
int main()
{
char str1[100001];
char str2[100001];
int i,j;
while(scanf("%s %s",str1,str2)!=EOF)
{
int len1,len2;
len1=strlen(str1);
len2=strlen(str2);
for(i=0;i<=len1;i++)
{
maxlen[i][0]=0;
}
for(j=0;j<=len2;j++)
{
maxlen[0][j]=0;
}
for(i=1;i<=len1;i++)
{
for(j=1;j<=len2;j++)
{
if(str1[i-1]==str2[j-1])
{
maxlen[i][j]=maxlen[i-1][j-1]+1;
}
else
{
maxlen[i][j]=Max(maxlen[i-1][j],maxlen[i][j-1]);
}
}
}
printf("%d\n",maxlen[len1][len2]);
}
}
边栏推荐
- Lightflow completed the compatibility certification with "daocloud Enterprise Cloud native application cloud platform"
- National standard gb28181 protocol easygbs video platform TCP active mode streaming exception repair
- What are the common categories of software testing?
- 软件测试测试常见分类有哪些?
- C - Common Subsequence
- Summary of wechat applet test points
- Design of four kinds of linear phase FIR filters -- complete set of Matlab source code
- 组合模式(Composite )
- P5733 【深基6.例1】自动修正
- Power Designer - Custom Comment button
猜你喜欢

10秒内完成火灾预警,百度智能云助力昆明官渡打造智慧城市新标杆

Power Designer - Custom Comment button

Biff TwinCAT can quickly detect the physical connection and EtherCAT network through emergency scan

Group counting practice experiment 9 -- using cmstudio to design microprogram instructions based on segment model machine (2)

Verilog中的系统任务(显示/打印类)--$display, $write,$strobe,$monitor

processsing 函数random

Mode pont
![[BSidesCF 2019]Kookie 1](/img/22/585d081668e67b8389a1b90aaebe9d.png)
[BSidesCF 2019]Kookie 1

OPLG: 新一代云原生可观测最佳实践
![HDU1724[辛普森公式求积分]Ellipse](/img/57/fb5098e150b5f3d91a5d0983a336ee.png)
HDU1724[辛普森公式求积分]Ellipse
随机推荐
Electron official docs series: References
Processing function translate (mousex, mousey) learning
Stream learning record
PostGIS geographic function
sql 将数据表b字段值赋值到数据表a中某一列
Electron official docs series: Distribution
mariadb学习笔记
P2393 yyy loves Maths II
Don't mess with full_ Case and parallel_ CASE
C - Common Subsequence
HDU 5860
Processing random generation line animation
【网络是怎么连接的】第二章(下):一个网络包的接收
Detailed explanation of C const: definition and use of C constant
D - 滑雪
5月产品升级观察站
Copy multiple Excel files and name them different
Deeply analyze the differences between dangbei box B3, Tencent Aurora 5S and Xiaomi box 4S
中科软外包一面
HDU 3709 Balanced Number