当前位置:网站首页>关于如何求两个字符串的最大公共子串的问题
关于如何求两个字符串的最大公共子串的问题
2022-08-09 00:00:00 【Kobe_G】
这是一个求字符串的最大公共子串的模板,此方法对于长度较短的字符串效率较高:
#include <stdio.h>
#include <string.h>
int f(char s1[],char s2[])
{
int a[100][100];
int len1 = strlen(s1);
int len2 = strlen(s2);
int i,j;
memset(a,0,sizeof(int)*100*100);
int max = 0;
for(i=1; i<=len1; i++){
for(j=1; j<=len2; j++){
if(s1[i-1]==s2[j-1]) {
a[i][j] = a[i-1][j-1]+1;
if(a[i][j] > max) max = a[i][j];
}
}
}
return max;
}
int main()
{
char a[100],b[100];
scanf("%s%s",a,b);
printf("%d\n", f(a,b));
return 0;
}
边栏推荐
猜你喜欢
随机推荐
面试题--数据库事务四大特性及事务的隔离级别
laravel框架之验证码控制器
C--《C和指针》第七章读书笔记
风控建模二:建模方案拟定
并发编程第10篇,CountDownLatch(计数器)和Semaphore(信号量)
并发专题第一篇,多线程快速入门和简单介绍
第四章 网络层
八 Node.js中使用MySQL
C#中构造函数的作用
Get the start time of the week
OSPF综合实验
C#在控制台应用程序中显示输出字节型数据
监听浏览器刷新事件
卷积神经网络反向传播直观理解
Get the start time and end time of the current month half a year ago
并发编程第8篇,AQS源码解读
并发编程第二篇,线程之间的通讯
Intelligent search baidu map and drag the picture circle
穿越派·派盘 + OmniFocus = 私人项目管理库
RHCSA--第二天