当前位置:网站首页>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]);
}
}
边栏推荐
- 【网络是怎么连接的】第二章(上): 建立连接,传输数据,断开连接
- A must for programmers, an artifact utools that can improve your work efficiency n times
- Processing 多面体变化
- 心脏滴血漏洞(CVE-2014-0160)分析与防护
- Mongodb of NoSQL - 03 mongodb CRUD
- MySQL 自定义函数时:This function has none of DETERMINISTIC, NO SQL 解决方案
- 倍福PLC实现绝对值编码器原点断电保持---bias的使用
- Biff TwinCAT can quickly detect the physical connection and EtherCAT network through emergency scan
- 详细讲解C语言11(C语言系列)
- Tiger Dao VC products are officially launched, a powerful supplement to seektiger ecology
猜你喜欢

ES6模块

Redis learning - 01 introduction, installation and configuration

机器学习笔记 - 时间序列的季节性

. Net Maui performance improvement

别乱用 FULL_CASE 和 PARALLEL_CASE
Adobe Acrobat阻止30款安全软件查看PDF文件 或存在安全风险

P5733 【深基6.例1】自动修正

Xiaobai lazy special-win10-win11 one click installation version

The El form item contains two inputs. Verify the two inputs
![[极客大挑战 2019]RCE ME 1](/img/66/e135f7e5a7cbdeb5b697f3939a3402.png)
[极客大挑战 2019]RCE ME 1
随机推荐
第十章 设置结构化日志记录(二)
ES6:迭代器
The El form item contains two inputs. Verify the two inputs
倍福PLC选型--如何看电机是多圈绝对值还是单圈绝对值编码器
Redis learning - 05 node JS client operation redis and pipeline pipeline
NoSQL mongodb - 02 mongodb server installation, mongodb shell, basic concepts and visualization tools
tauri vs electron
NoSQL mongodb - 01 introduction to NoSQL and mongodb
Lightflow completed the compatibility certification with "daocloud Enterprise Cloud native application cloud platform"
KVM video card transparent transmission -- the road of building a dream
记一次phpcms9.6.3漏洞利用getshell到内网域控
C# const详解:C#常量的定义和使用
postgis 地理化函数
无人机遥感在森林监测的部分应用研究案例总结
Redis learning - 03 transaction
Angle de calcul POSTGIS
Source code learning: atomicinteger class code internal logic
黑马笔记---常用API
POJ 3070 Fibonacci
[BSidesCF 2019]Kookie 1