hdu 2203 亲和串
来源:互联网 发布:耐克淘宝店装修风格 编辑:程序博客网 时间:2024/06/05 08:07
http://acm.hdu.edu.cn/showproblem.php?pid=2203
裸的字符串匹配问题
AC代码:
#include <algorithm>#include <iostream>#include <string.h>#include <stdio.h>using namespace std;int next[200010];char s[200010],t[100010];void getnext(){ int i = 0, j = -1, len = strlen(t); next[0] = -1; while(i<len){ if(j == -1 || t[i] == t[j]){ i++,j++; next[i] = j; } else j = next[j]; }}bool KMP(){ int i=0, j=0; int l1 = strlen(s), l2 = strlen(t); while(i < l1){ if(j == -1 || s[i] == t[j]){ i++; j++; } else j = next[j]; if(j >= l2) return true; } return false;}int main(){// freopen("in.txt","r",stdin); while(scanf("%s%s",s,t) == 2){ int l = strlen(s),tmp = l; for(int i=0; i<tmp; i++) s[l++] = s[i]; s[l] = '\0'; getnext(); bool ans = KMP(); ans ? cout << "yes\n" : cout << "no\n"; } return 0;}
0 0
- HDU 2203 亲和串
- HDU 2203 亲和串
- HDU - 2203 亲和串
- hdu 2203 亲和串
- hdu 2203 亲和串
- HDU 2203 亲和串
- HDU-亲和串-2203
- hdu 2203 亲和串
- hdu 2203 亲和串
- hdu 2203 亲和串
- hdu 2203 亲和串
- HDU 2203 亲和串
- HDU 2203【亲和串】
- hdu 2203 亲和串
- HDU 2203 亲和串
- hdu 2203亲和串
- HDU 2203 亲和串
- HDU - 2203 亲和串
- 92SlidingDrawer控件介绍
- 视频下载工具“硕鼠”与遨游浏览器的比拼(图文)
- Java线程:线程的调度-休眠
- 4384: X++
- 顺时针打印矩阵
- hdu 2203 亲和串
- Android中RelativeLayout各个属性
- linux setitimer
- ThinkPHP3.1.3源码分析(五) App.class.php
- 数据库的基本操作及数据库与c#的连接
- [C++]LeetCode: 63 Subsets
- <mvc:view-controller 用法
- java封装之访问权限控制
- Tiny210V2(S5PV210)的U-boot分析