当前位置:网站首页>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]);
}
}
边栏推荐
- Source code learning: atomicinteger class code internal logic
- National standard gb28181 protocol easygbs cascaded universal vision platform, how to deal with live message 403?
- Do you know the limitations of automated testing?
- Learning Processing Zoog
- 外观模式(Facade)
- Chapter 01_ Installation and use of MySQL under Linux
- ES6:Map
- C - Common Subsequence
- What should the software test report include? Interview must ask
- 【shell】生成指定日期之间的字符串
猜你喜欢
随机推荐
Record a phpcms9.6.3 vulnerability to use the getshell to the intranet domain control
How does easygbs solve the abnormal use of intercom function?
G - Cow Bowling
中国剩余定理模板题 互质与非互质
map 取值
Detailed explanation of C const: definition and use of C constant
Electron official docs series: Development
QT .pri 的建立与使用
倍福PLC基于CX5130实现数据的断电保持
OPLG: 新一代云原生可观测最佳实践
processing 函数translate(mouseX, mouseY)学习
Stream learning record
5月产品升级观察站
Angle de calcul POSTGIS
Common creation and usage of singletons
What are the common categories of software testing?
【网络是怎么连接的】第二章(下):一个网络包的接收
利用scrapy爬取句子迷网站优美句子存储到本地(喜欢摘抄的人有福了!)
【shell】生成指定日期之间的字符串
倍福将EtherCAT模块分到多个同步单元运行--Sync Units的使用
![[BSidesCF 2019]Kookie 1](/img/22/585d081668e67b8389a1b90aaebe9d.png)








