当前位置:网站首页>关于如何求两个字符串的最大公共子串的问题
关于如何求两个字符串的最大公共子串的问题
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;
}
边栏推荐
猜你喜欢
随机推荐
pytorch 使用torch.autograd.grad 求导
Ubuntu下Docker安装Redis (快速简便)
穿越派·派盘 + OmniFocus = 私人项目管理库
八 Node.js中使用MySQL
markdown:如何绘思维导图
Idea碰到的问题总结
conda xgboost 安装 jupyter notebook
指南针股票软件股票开户安全嘛
RHCSA--第二天
Laravel框架之数据库配置
gptp协议
2017年10月历史文章汇总
MySQL导入导出数据库
HCIP2--RIP实验
Laravel框架之文件上传
ADXL345静止时振动值不归零的问题
OSPF总结作业
一种新的测转速的方法
禅道数据库异机访问,远程连接,navicat连接
第六章 物理层









