#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue> using namespace std; void getnext(char *t, int *next, int lent)
{
int i = 0, j = -1;
next[0] = -1;
while (i < lent)
if (j == -1 || t[i] == t[j])
++i, ++j, next[i] = j;
else
j = next[j];
} int kmp(char *s, char *t, int *next, int lens, int lent)
{ int i = 0, j = 0;
while (i < lens)
{
if (-1 == j || s[i] == t[j])
i++, j++;
else
j = next[j];
if (j == lent) return 1;
}
return 0;
} int main()
{
char t[100],s[1000];
int next[100];
printf("Enter模式串,主串\n");
scanf("%s",t);
gets(s);
int lent = strlen(t);
int lens = strlen(s);
getnext(t, next, lent);
printf("%d\n1表示成功", kmp(s, t, next, lens, lent));
return 0;
}

最新文章

  1. R中数据拆分和整合
  2. 二 Java利用等待/通知机制实现一个线程池
  3. Mysql与Redis的同步实践
  4. Linux休眠,挂起,待机,关机的区别及相关命令
  5. C#语法杂谈
  6. MVC学习系列——ActionResult扩展
  7. 反射---Java高级开发必须懂的
  8. windows+apache2.2.9+php5.4.41+mysql安装
  9. jcSQL词法分析器对字符串token的解析
  10. js移动端向左滑动出现删除按钮
  11. java中volatile的简单理解
  12. 【XSY2715】回文串 树链剖分 回文自动机
  13. android 事件反拦截
  14. .NET持续集成与自动化部署之路第二篇——使用NuGet.Server搭建公司内部的Nuget(包)管理器
  15. 浅谈 equals 和 == 的区别
  16. 小程序 wepy wx.createAnimation 向右滑动渐入渐出
  17. MapServer和GeoServer对比
  18. The Begining
  19. MIT6.006Lec02:DocumentDistance
  20. linux 同步IO: sync、fsync与fdatasync

热门文章

  1. jQuery jQuery on()方法
  2. Spring Cloud(2):搭建Eureka
  3. 从零开始的全栈工程师——js篇2.4
  4. ArrayList,Vector, LinkedList 的存储性能和特性
  5. Android中渐变图片失真的解决方案
  6. 《Python高效开发实战》实战演练——基本视图3
  7. 新客户上云 - 来自 Azure 技术支持部门的忠告
  8. jQuery-显示与隐藏不用判断的快捷方法
  9. [Asp.Net] Global.asax
  10. linux 命令——48 watch (转)