kmp Writings on the Wall Virtual Judge5876
来源:互联网 发布:北斗卫星定位软件 编辑:程序博客网 时间:2024/06/02 05:10
#include <algorithm>#include <cstring>#include <cstdio>char str[2][50005];int next[50005];void getnext( char *str ){ int i, j; int len=strlen( str ); i=0, j=-1; next[0]=-1; while( i<len ) { if( j==-1 || str[i]==str[j] ) { i++;j++; next[i]=j; } else j=next[j]; }}int kmp(){ int i=0, j=0, ans=0; int sublen=strlen( str[1] ); int len=strlen( str[0] ); while( i<len ) { if( str[1][j]==str[0][i] || j==-1 ) { i++;j++; } else j=next[j]; } while( j ) { j=next[j]; ans++; } return ans;}int main(){ int t; scanf( "%d", &t ); while( t-- ) { scanf( "%s%s", str[0], str[1] ); getnext( str[1] ); printf( "%d\n", kmp()+1 ); } return 0;}
0 0
- kmp Writings on the Wall Virtual Judge5876
- UVALive 5876 - Writings on the Wall 【KMP】
- UVALive 5876 Writings on the Wall
- Across the wall on linux
- The Handwriting on the Cheese Wall
- 短语:the writing is on the wall
- 2405. Mirror, Mirror on the Wall
- Date on Database: Writings 2000-2006
- 做一只墙上的苍蝇(a fly on the wall)
- Who Has The Best Tech Department On Wall Street?
- SDUT——Mirror, Mirror on the Wall 解题报告
- Pink Floyd -- The Wall
- hdu2124 Repair the Wall
- hdu1543 Paint the Wall
- hdu1543 Paint the Wall
- Repair the Wall+贪心
- A. The Wall
- Paint The Wall hdu4391
- Microcomputer Principle - Memory Reordering
- Android4学习-高级编程读书笔记开始篇
- c++ 学习 随笔七
- NDK DEBUG方法
- 凡事预则立,不预则废
- kmp Writings on the Wall Virtual Judge5876
- 互联网电商退货问题让人头痛
- 设计模式——策略模式
- 屏幕适配
- 使用ALTER USER命令修改用户的密码、密码过期,锁定,解锁
- Required red Mark on a visualforce page -自定义字段如何必填标红
- 【Android】查看内存
- 一些常用接口地址
- Android实时获取音量(单位:分贝)