博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
string matching(拓展KMP)
阅读量:5010 次
发布时间:2019-06-12

本文共 1566 字,大约阅读时间需要 5 分钟。

Problem Description
String matching is a common type of problem in computer science. One string matching problem is as following:
Given a string 
s[0len1], please calculate the length of the longest common prefix of s[ilen1] and s[0len1] for each i>0.
I believe everyone can do it by brute force.
The pseudo code of the brute force approach is as the following:
We are wondering, for any given string, what is the number of compare operations invoked if we use the above algorithm. Please tell us the answer before we attempt to run this algorithm.
 

 

Input
The first line contains an integer 
T, denoting the number of test cases.
Each test case contains one string in a line consisting of printable ASCII characters except space.
1T30
* string length 106 for every string
 

 

Output
For each test, print an integer in one line indicating the number of compare operations invoked if we run the algorithm in the statement against the input string.
 

 

Sample Input
3 _Happy_New_Year_ ywwyww zjczzzjczjczzzjc
 

 

Sample Output
17 7 32
代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
const int maxn=1e6+5;typedef long long ll;using namespace std;ll ans;void pre_EKMP(char x[],int m,ll next[]){ next[0]=m; int j=0; while(j+1
>T; while(T--) { scanf("%s",str); int len=strlen(str); ans=0; pre_EKMP(str,len,nxt); for(int t=1;t

 

 

转载于:https://www.cnblogs.com/Staceyacm/p/11305505.html

你可能感兴趣的文章
display:flow-root
查看>>
判读字符串是否为空的全局宏-分享
查看>>
iOS中Block的基础用法
查看>>
mac 终端 使用ftp命令
查看>>
22-reverseString-Leetcode
查看>>
Centos 开机自动联网
查看>>
cocos2dx使用lua和protobuf
查看>>
HDOJ 5630 Rikka with Chess
查看>>
netcore2.1 在后台运行一个任务
查看>>
PostgreSQL pg_hba.conf 文件简析
查看>>
android o logcat read: unexpected EOF!
查看>>
[Scrum]2010/12/28 —— 第一天!
查看>>
ASP.NET MVC模式 温习(一)排除MVC模式误区
查看>>
Mysql的read_only 只读属性说明 (运维笔记)
查看>>
DOCKER 从入门到放弃(五)
查看>>
Python 多线程学习
查看>>
appcan官方ajax
查看>>
获取NVIDIA显卡的温度
查看>>
Dijkstra算法
查看>>
Deep Learning 9: Performance
查看>>