两种方法     首先是纯KMP

#include<stdio.h>

#include<string.h>

#include<iostream>

using namespace std;





char str1[200010],str2[100010];

int next[100010];

int get()

{

next[0]=-1;

int j=0;

int k=-1;

int len=strlen(str2);

while(j<len-1)

{

if(k==-1||str2[k]==str2[j])

{

j++;

k++;

next[j]=k;

}

else k=next[k];

}

return 0;

}

int main()

{

int i,j;

while(~scanf("%s%s",str1,str2))

{

get();

char str[100010];

strcpy(str,str1);

strcat(str1,str);

//printf("&&&&\n");

int len1=strlen(str1);

int len2=strlen(str2);

int i=j=0;

while(i<len1&&j<len2)

{

if(j==-1||str1[i]==str2[j])

{

i++;

j++;

}

else j=next[j];

}

if(j==len2) printf("yes\n");

else printf("no\n");

}

return 0;

}

以下是用了STL里面的函数

#include<stdio.h>

#include<string.h>

#include<iostream>

using namespace std;





int main()

{

char str1[200010],str2[100010],str[100010];

int i,j;

while(~scanf("%s%s",str1,str2))

{

strcpy(str,str1);

strcat(str1,str);

if(strstr(str1,str2)) printf("yes\n");

else printf("no\n");



return 0;

}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

hdu2203 KMP水的问题的更多相关文章

  1. poj-2406(kmp水题)

    题意:定义一个a*b=字符串a连接字符串b:给你一个字符串s,问你这个字符串最多能用多少个字符串t连接得到:例如:aaaa=4个a构成: 解题思路:kmp水题,next数组除了查找字串以外最广泛的一种 ...

  2. POJ 3641 Oulipo KMP 水题

    http://poj.org/problem?id=3461 直接KMP就好.水题 #include<cstdio> #include<cstring> const int M ...

  3. hdu 4763 Theme Section(KMP水题)

    Theme Section Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  4. (KMP 水)Wow! Such Doge! -- hdu -- 4847

    http://acm.hdu.edu.cn/showproblem.php?pid=4847 Wow! Such Doge! Time Limit:1000MS     Memory Limit:32 ...

  5. HDU2203(KMP入门题)

    亲和串 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  6. 计蒜客 阿里天池的新任务—简单( KMP水 )

    链接:传送门 思路:KMP模板题,直接生成 S 串,然后匹配一下 P 串在 S 串出现的次数,注意处理嵌套的情况即可,嵌套的情况即 S = "aaaaaa" ,P = " ...

  7. [hdu2594]kmp水题

    题意:求最长的a的前缀同时满足是b的后缀,把a,b连在一起,kmp跑一下,迭代next直到长度小于等于a,b长度的最小值为止,即为答案. #pragma comment(linker, "/ ...

  8. [hdu2087]kmp水题

    题意:求模板串在文本串中出现的次数(位置无交叉).只需在找到的时候把模板串指针归0即可. #pragma comment(linker, "/STACK:10240000,10240000& ...

  9. HDU - 2203 KMP水题

    循环移位的套路操作就是一份折开变两份 /*H E A D*/ void match(){ int n=strlen(T+1); int m=strlen(P+1); int j=0; rep(i,1, ...

随机推荐

  1. 【C语言探索之旅】 第一部分第八课:第一个C语言小游戏

    ​ 内容简介 1.课程大纲 2.第一部分第八课:第一个C语言小游戏 3.第一部分第九课预告: 函数 课程大纲 我们的课程分为四大部分,每一个部分结束后都会有练习题,并会公布答案.还会带大家用C语言编写 ...

  2. 苹果WatchKit轻松入门

    背景 前段时间苹果Apple推出 WatchKit,用于开发Apple Watch应用,同时也推出了 Xcode6.2 Beta(非稳定版,好期待稳定版)版本用于开发 Watch App.Apple ...

  3. SRM 590 DIV1

    转载请注明出处,谢谢viewmode=contents">http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlov ...

  4. Linux互斥和同步应用程序(四):posix互斥信号和同步

           [版权声明:尊重原创.转载请保留源:blog.csdn.net/shallnet 要么 .../gentleliu,文章仅供学习交流,请勿用于商业用途]          在前面讲共享内 ...

  5. Binary System

    Description Usually we use number in the decimal system, for it is so convenient for us to remember ...

  6. port大全及port关闭方法

    在网络技术中,port(Port)大致有两种意思:一是物理意义上的port,比方,ADSL Modem.集线器.交换机.路由器用于连接其它网络设备的接口,如RJ-45port.SCport等等.二是逻 ...

  7. 每天的学习经验:SharePoint 2013 定义自己添加的产品清单。Callout菜单项、文档关注、SharePoint服务机端对象模型查询

    前言: 前一段时间一直都比較忙.没有什么时间进行总结,刚好节前项目上线.同一时候趁着放假能够好好的对之前遇到的一些问题进行总结. 主要内容有使用SharePoint服务端对象模型进行查询.为Share ...

  8. [译]MVC应用程序生命周期

    原文:MVC Application Lifecycle 来一探究竟在MVC应用程序中参与请求处理的各个不同组件. 目录: 序言 背景 UrlRoutingModule RouteHandler Mv ...

  9. (四)左右ng-app自己主动bootstrap相框

    博客之前 (三)ng-app的使用困惑和angularJS框架的自己主动载入 提出了使用ng-app指令的情况.之前认为出现第4和第5种情况非常奇怪,由于仅仅看到了现象,没有看到本质.JS错误.最直观 ...

  10. ssis t-sql返回值

    原文:ssis t-sql返回值 sql类似如下,不需要使用return 语句,SQL语句的ConnectionType必须是"ADO.NET" select @proID=fie ...