hdu 2203 亲和串 (kmp入门)
来源:互联网 发布:logmett是什么软件 编辑:程序博客网 时间:2024/05/16 08:56
#include<iostream>#include<math.h>#include<stdio.h>#include<algorithm>#include<string.h>#include<vector>#include<map>using namespace std;//typedef long long lld;const int oo=0x3f3f3f3f;//const lld OO=1LL<<61;const int MOD=(1e9)+7;const int maxn=100005;int next[maxn];char s1[maxn<<1],s2[maxn];void get_next(int len){ int i=0;next[i]=-1; int j=-1; while(i<len-1) { if(j==-1||s2[i]==s2[j]) { i++;j++; next[i]=j; } else j=next[j]; }}int kmp(int pos,int len1,int len2){ int i=pos; int j=0; while(i<len1&&j<len2) { if(j==-1||s1[i]==s2[j]) { i++; j++; } else j=next[j]; } if(j>=len2) return i-len2; else return -1;}int main(){ while(scanf("%s%s",s1,s2)!=EOF) { int len1=strlen(s1); int len2=strlen(s2); if(len2>len1) { puts("no"); continue; } get_next(len2); for(int i=0;i<len1;i++) { s1[i+len1]=s1[i]; } s1[2*len1]='\0'; int f=kmp(0,2*len1,len2); if(f!=-1) puts("yes"); else puts("no"); } return 0;}/**abcd-> abcdabcabcda*/
0 0
- hdu 2203 亲和串 (kmp入门)
- hdu 2203 亲和串 KMP入门
- HDU-2203 亲和串(KMP入门)
- Kmp 入门题 hdu 2203 亲和串
- KMP hdu-2203-亲和串
- HDU 2203 亲和串 KMP
- hdu 2203 亲和串 kmp
- hdu 2203 亲和串(KMP)
- 亲和串 - HDU 2203 KMP
- 【HDU】2203 亲和串 KMP
- HDU 2203(KMP) 亲和串
- HDU 2203 亲和串 (KMP)
- hdu 2203 亲和串 KMP
- HDU - 2203 亲和串(Kmp)
- HDU 2203 亲和串 KMP
- kmp入门--hd 2203 亲和串
- hdu 2203 亲和串(KMP|strstr())
- HDU 2203 亲和串(KMP:循环移位)
- 过节前的数据库系统检查
- 步步情天
- 支付宝抢红包神器
- 分位数(quantile)与分位函数(quantile function)
- [Leetcode 8, Easy] String to Integer
- hdu 2203 亲和串 (kmp入门)
- Java class文件的JDK编译版本号
- 浮点数的二进制表示
- 解决方案:Warning: phpinfo(): It is not safe to rely on the system's timezone settings.
- 我该如何向非技术人解释SQL注入?
- jasperreports报表Flash展现
- poj 2406 Power Strings
- 国外程序员整理的机器学习资源大全
- Qt Qsplitter 问题处理