当前位置:网站首页>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]);
}
}
边栏推荐
- 解中小企业之困,百度智能云打个样
- 别乱用 FULL_CASE 和 PARALLEL_CASE
- 5月产品升级观察站
- Electron official docs series: Get Started
- HDU 3555 Bomb
- P5733 [deep foundation 6. example 1] automatic correction
- 【网络是怎么连接的】第二章(下):一个网络包的接收
- P2393 yyy loves Maths II
- Design of four kinds of linear phase FIR filters -- complete set of Matlab source code
- processing 随机生成线动画
猜你喜欢

利用scrapy爬取句子迷网站优美句子存储到本地(喜欢摘抄的人有福了!)

Machine learning notes - seasonality of time series

Solution of Splunk iowait alarm

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

Dark horse notes - Common APIs

ES6:迭代器

享元模式(Flyweight)

Deep parsing MySQL binlog

Processing random generation line animation

ES6:Map
随机推荐
中科软外包一面
倍福EtherCAT Xml描述文件更新和下载
Sinotech software outsourcing
倍福TwinCAT通过Emergency Scan快速检测物理连接和EtherCAT网络
Processing 多面体变化
Accumulation of interview questions
橋接模式(Bridge)
postgis 地理化函数
Processing function translate (mousex, mousey) learning
第十章 设置结构化日志记录(二)
Guacamole installation
Don't mess with full_ Case and parallel_ CASE
OPLG: 新一代云原生可观测最佳实践
POJ 3070 Fibonacci
倍福将EtherCAT模块分到多个同步单元运行--Sync Units的使用
Electron official docs series: Development
HDU1724[辛普森公式求积分]Ellipse
HDU 3709 Balanced Number
[BSidesCF 2019]Kookie 1
【网络是怎么连接的】第一章:浏览器生成消息