KMP算法(模板题)

KMP算法(模板题),第1张

KMP算法(模板题)

 题目来源:

https://ac.nowcoder.com/acm/contest/27589/A

参考博客:

 

https://blog.csdn.net/weixin_46007276/article/details/104372119?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164290454516780271917298%2522

#include//题目大意两个字符串中寻找字串,并求第二个字符串中的前缀最大长度 
using namespace std;
int b[1000005];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    string s1,s2;
    cin>>s1>>s2;//输入两个字符串 
    int len1 = s1.size(), len2 = s2.size();//用一个size取字符串长度,减少时间复杂度
	//取next数组,这里用b数组表示,原因是在c++的万能头中有next的数据流 
    int j=0;
    int k=-1;//负一版本 
    b[0]=-1;
    while(j					
										


					

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5711879.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存