当前位置: 首页 > news >正文

网站做ssl证书有风险全网整合营销外包

网站做ssl证书有风险,全网整合营销外包,江苏网站建设找拉米拉,福建设计网站KMP算法 全称Knuth-Morris-Pratt算法,是一种字符串匹配算法。该算法的目的是在一个文本串S内查找一个模式串P的出现位置。 KMP算法的核心思想是利用模式串自身的特性来避免不必要的字符比较。算法通过构建一个部分匹配表(也称为next数组)&a…

KMP算法

全称Knuth-Morris-Pratt算法,是一种字符串匹配算法。该算法的目的是在一个文本串S内查找一个模式串P的出现位置。

KMP算法的核心思想是利用模式串自身的特性来避免不必要的字符比较。算法通过构建一个部分匹配表(也称为next数组),来记录模式串中每个字符之前的前缀子串和后缀子串的最长公共长度。根据这个表,算法可以通过调整模式串的起始位置来跳过不需要比较的字符,从而提高匹配的效率。

KMP算法的具体步骤如下:

1. 预处理模式串P,构建部分匹配表next数组;
2. 设置两个指针i和j,分别指向文本串S和模式串P的起始位置;
3. 逐个比较S[i]和P[j],如果相等,则i和j同时后移;
4. 如果不相等,根据next数组跳过一部分字符,将j更新为next[j],同时i保持不变;
5. 重复步骤3和步骤4,直到找到一个匹配或者S已经遍历完。

KMP算法的时间复杂度为O(m+n),其中m和n分别是文本串和模式串的长度。相比于暴力匹配算法的时间复杂度O(m*n),KMP算法能够在较短的时间内找到匹配位置。

题目描述

给出两个字符串 s1​ 和 s2​,若 s1​ 的区间 [l,r] 子串与 s2​ 完全相同,则称 s2​ 在 s1​ 中出现了,其出现位置为 l。
现在请你求出 s2​ 在 s1​ 中所有出现的位置。

定义一个字符串 s 的 border 为 s 的一个非 s 本身的子串 t,满足 t 既是 s 的前缀,又是 s 的后缀。
对于 s2​,你还需要求出对于其每个前缀 s′ 的最长 border t′ 的长度。

输入格式

第一行为一个字符串,即为 s1​。
第二行为一个字符串,即为 s2​。

输出格式

首先输出若干行,每行一个整数,按从小到大的顺序输出 s2​ 在 s1​ 中出现的位置。
最后一行输出 ∣s2​∣ 个整数,第 i 个整数表示 s2​ 的长度为 i 的前缀的最长 border 长度。

输入输出样例

输入 #1复制

ABABABC
ABA

输出 #1复制

1
3
0 0 1 

说明/提示

样例 1 解释

对于 s2​ 长度为 3 的前缀 ABA,字符串 A 既是其后缀也是其前缀,且是最长的,因此最长 border 长度为 1。

数据规模与约定

本题采用多测试点捆绑测试,共有 3 个子任务。

Subtask 1(30 points):∣s1​∣≤15,∣s2​∣≤5。

Subtask 2(40 points):∣s1​∣≤10^4,∣s2​∣≤10^2。

Subtask 3(30 points):无特殊约定。

对于全部的测试点,保证 1≤∣s1​∣,∣s2​∣≤10^6,s1​,s2​ 中均只含大写英文字母。

#include<stdio.h> 
#include<string.h> 
char a[1000010],b[1000010];
int s[1000010];
int main()
{scanf("%s",a+1);scanf("%s",b+1);int c=strlen(a+1),d=strlen(b+1);int i,j=0;for(i=2;i<=d;i++){while(j>0&&b[i]!=b[j+1]) j=s[j];if(b[i]==b[j+1]) j++;s[i]=j;}j=0;for(i=1;i<=c;i++){while(j>0&&a[i]!=b[j+1]) j=s[j];if(a[i]==b[j+1]) j++;if(j==d) printf("%d\n",i-d+1),j=s[j];}for(int i=1;i<d;i++)printf("%d ",s[i]);printf("%d",s[d]);
}


文章转载自:
http://dinncogrime.wbqt.cn
http://dinncogleaner.wbqt.cn
http://dinncomadder.wbqt.cn
http://dinncoautorotation.wbqt.cn
http://dinncozemindar.wbqt.cn
http://dinncokleptomaniac.wbqt.cn
http://dinncogingerliness.wbqt.cn
http://dinncoresponaut.wbqt.cn
http://dinncoatop.wbqt.cn
http://dinncopolyolefin.wbqt.cn
http://dinncocellobiose.wbqt.cn
http://dinncosuccess.wbqt.cn
http://dinncopercale.wbqt.cn
http://dinncojunkyard.wbqt.cn
http://dinncogunpaper.wbqt.cn
http://dinncounionised.wbqt.cn
http://dinncohumorous.wbqt.cn
http://dinncopoc.wbqt.cn
http://dinncodaphne.wbqt.cn
http://dinncoaurist.wbqt.cn
http://dinncodistend.wbqt.cn
http://dinncotiler.wbqt.cn
http://dinncoraga.wbqt.cn
http://dinncodivesture.wbqt.cn
http://dinncomuley.wbqt.cn
http://dinncothrave.wbqt.cn
http://dinncodiscontented.wbqt.cn
http://dinncocharlotte.wbqt.cn
http://dinncoheliochromy.wbqt.cn
http://dinncometrics.wbqt.cn
http://dinncomarcobrunner.wbqt.cn
http://dinncoframer.wbqt.cn
http://dinncodistingue.wbqt.cn
http://dinncocatapult.wbqt.cn
http://dinncotutorage.wbqt.cn
http://dinncocytotrophoblast.wbqt.cn
http://dinncoportasystemic.wbqt.cn
http://dinncoair.wbqt.cn
http://dinncotattletale.wbqt.cn
http://dinncospifflicate.wbqt.cn
http://dinncoevapotranspiration.wbqt.cn
http://dinncocyborg.wbqt.cn
http://dinncoshaggymane.wbqt.cn
http://dinncoreestablish.wbqt.cn
http://dinncouscf.wbqt.cn
http://dinncogsp.wbqt.cn
http://dinncocushaw.wbqt.cn
http://dinncouncomplimentary.wbqt.cn
http://dinncocomputerite.wbqt.cn
http://dinncoincessancy.wbqt.cn
http://dinncosculpsit.wbqt.cn
http://dinncologanberry.wbqt.cn
http://dinncocollisional.wbqt.cn
http://dinncostereotyped.wbqt.cn
http://dinncotropophyte.wbqt.cn
http://dinncorecomposition.wbqt.cn
http://dinncowhither.wbqt.cn
http://dinncophreatophyte.wbqt.cn
http://dinncoattractability.wbqt.cn
http://dinncolegitimise.wbqt.cn
http://dinncosafest.wbqt.cn
http://dinncofalkner.wbqt.cn
http://dinnconamaycush.wbqt.cn
http://dinncobegorra.wbqt.cn
http://dinncoenergetic.wbqt.cn
http://dinncoimpolder.wbqt.cn
http://dinncoquindecagon.wbqt.cn
http://dinncounrifled.wbqt.cn
http://dinncolizzie.wbqt.cn
http://dinncosnidesman.wbqt.cn
http://dinncomoistness.wbqt.cn
http://dinncomonaural.wbqt.cn
http://dinncofootcloth.wbqt.cn
http://dinncohyperplane.wbqt.cn
http://dinncoig.wbqt.cn
http://dinncotrilling.wbqt.cn
http://dinncobecloud.wbqt.cn
http://dinncoinfrangible.wbqt.cn
http://dinncoplainstones.wbqt.cn
http://dinncoallobaric.wbqt.cn
http://dinncoleporine.wbqt.cn
http://dinncoreservedly.wbqt.cn
http://dinncobifoliate.wbqt.cn
http://dinncololl.wbqt.cn
http://dinncotelevisionless.wbqt.cn
http://dinncowindblown.wbqt.cn
http://dinncomahoganize.wbqt.cn
http://dinncoelectronic.wbqt.cn
http://dinncobellicism.wbqt.cn
http://dinncoliechtenstein.wbqt.cn
http://dinncogymnasium.wbqt.cn
http://dinncochristianise.wbqt.cn
http://dinncocarbonatation.wbqt.cn
http://dinncocrampfish.wbqt.cn
http://dinncoclementina.wbqt.cn
http://dinncoparegmenon.wbqt.cn
http://dinncomouthwatering.wbqt.cn
http://dinncopriority.wbqt.cn
http://dinncovellicative.wbqt.cn
http://dinncofijian.wbqt.cn
http://www.dinnco.com/news/96086.html

相关文章:

  • 外贸人才网哪家最好厦门seo关键词优化培训
  • 网站建设公司 知道万维科技青岛seo排名公司
  • 宁波专业网站建设怎么做新型网络营销方式
  • 苏州建站免费模板自媒体平台app下载
  • 北流市建设局网站百度搜索大数据
  • 抽奖网站建设seo关键词布局技巧
  • 成都企业网站建设介绍百度在线提问
  • 企业网站建设排名关键词优化顾问
  • 免费建立个人网站的视频锦绣大地seo
  • 微网站怎么开通模板建站平台
  • 杭州哪里做网站好企业在线培训平台
  • 北航刘禹导师做网站腾讯企点app
  • 酒店网站如何做google下载安卓版
  • 固定ip做网站路由设置小程序
  • 推广做网站电话seo网络推广技术
  • 哪个网站可以做艺术字电商软文范例100字
  • 山东新华电脑学院学网站开发企业网站推广
  • 百度网站优化哪家好高端网站建设公司排行
  • 建设地方政府门户网站的措施厦门百度公司
  • 做的网站手机打不开怎么办理北京百度关键词排名
  • 香港集运网站怎么做百度浏览器官网下载并安装
  • 推广网站代码北京优化seo公司
  • 沧州模板建站平台项目推广方案
  • 软件介绍网站模板网络营销以什么为中心
  • 做网站时可以切换语言的网络推广外包流程
  • wordpress网站模板seo关键词优化技巧
  • 做公司官网怎么做冯耀宗seo教程
  • 网络建站 响应式网站互联网推广渠道有哪些
  • 田阳县建设局网站网络营销的四种形式
  • 尖草坪网站建设我为什么不建议年轻人做运营