当前位置:网站首页>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]);
}
}
边栏推荐
- National standard gb28181 protocol easygbs video platform TCP active mode streaming exception repair
- Electron official docs series: Get Started
- 别乱用 FULL_CASE 和 PARALLEL_CASE
- C - Common Subsequence
- Detailed explanation of C const: definition and use of C constant
- Design of four kinds of linear phase FIR filters -- complete set of Matlab source code
- Photoshop 2022 23.4.1增加了哪些功能?有知道的吗
- Stream learning record
- tauri vs electron
- QT .pri 的建立与使用
猜你喜欢

【网络是怎么连接的】第二章(中):一个网络包的发出

倍福PLC选型--如何看电机是多圈绝对值还是单圈绝对值编码器

倍福PLC通过程序获取系统时间、本地时间、当前时区以及系统时间时区转换

详细讲解C语言10(C语言系列)

Electron official docs series: Processes in Electron

ES6:迭代器

processing 函数translate(mouseX, mouseY)学习
![Vivado 错误代码 [DRC PDCN-2721] 解决](/img/de/ce1a72f072254ae227fdcb307641a2.png)
Vivado 错误代码 [DRC PDCN-2721] 解决

Use the script to crawl the beautiful sentences of the sentence fan website and store them locally (blessed are those who like to excerpt!)

Deep parsing MySQL binlog
随机推荐
B - Bridging signals
tauri vs electron
This function has none of deterministic, no SQL solution
Electron official docs series: Best Practices
QT . Establishment and use of pri
享元模式(Flyweight)
opencv高速下载
Processsing function random
Echart堆叠柱状图:色块之间添加白色间距效果设置
Goto statement to realize shutdown applet
J - Wooden Sticks poj 1065
HDU 3555 Bomb
装饰器(Decorator)
首批通过!百度智能云曦灵平台获信通院数字人能力评测权威认证
Electron official docs series: Examples
倍福PLC旋切基本原理和应用例程
Go 结构体方法
Detailed explanation of C const: definition and use of C constant
postgis 地理化函数
Stream learning record