当前位置:网站首页>C - Common Subsequence
C - Common Subsequence
2022-06-26 12:40: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]);
}
}
边栏推荐
- . Net Maui performance improvement
- 第01章_Linux下MySQL的安装与使用
- Openlayers drawing dynamic migration lines and curves
- Research and development practice of Kwai real-time data warehouse support system
- Redis learning - 01 introduction, installation and configuration
- 轻流完成与「DaoCloud Enterprise 云原生应用云平台」兼容性认证
- 倍福PLC通过MC_ReadParameter读取NC轴的配置参数
- P5733 【深基6.例1】自动修正
- C# const详解:C#常量的定义和使用
- Stream流学习记录
猜你喜欢
随机推荐
黑马笔记---常用API
map 取值
Adobe Acrobat阻止30款安全软件查看PDF文件 或存在安全风险
C# const详解:C#常量的定义和使用
机组实践实验8——使用CMStudio设计基于基本模型机微程序指令(1)
Solution of Splunk iowait alarm
Deeply analyze the differences between dangbei box B3, Tencent Aurora 5S and Xiaomi box 4S
【网络是怎么连接的】第二章(上): 建立连接,传输数据,断开连接
tauri vs electron
Stream流学习记录
Less than 40 lines of code to create a blocprovider
KVM video card transparent transmission -- the road of building a dream
System tasks (display / print class) in Verilog - $display, $write, $strobe, $monitor
Research and development practice of Kwai real-time data warehouse support system
Lightflow completed the compatibility certification with "daocloud Enterprise Cloud native application cloud platform"
P5733 【深基6.例1】自动修正
心脏滴血漏洞(CVE-2014-0160)分析与防护
sql 将数据表b字段值赋值到数据表a中某一列
倍福TwinCAT3实现CSV、TXT文件读写操作
【网络是怎么连接的】第一章:浏览器生成消息