POJ_2752_KMP
http://poj.org/problem?id=2752
求字符串的字串,使前缀后缀都为这个字串,按字母数量排序输出数量。
用了KMP的未优化的next数组。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std; char a[];
int ans[],next[]; void get_next(int len)
{
int i = ,j = -;
next[] = -;
while(i < len)
{
if(j == - || a[i] == a[j])
{
++i;
++j;
next[i] = j;
}
else j = next[j];
}
}
int main()
{
while(~scanf("%s",a))
{
int cnt = ,len = strlen(a);
int now = len;
get_next(len);
while(now != )
{
now = next[now];
ans[cnt++] = now;
}
for(int i = cnt-;i >= ;i--) printf("%d ",ans[i]);
printf("%d\n",len);
}
return ;
}
POJ_2752_KMP的更多相关文章
随机推荐
- win7技巧
win7技巧 快捷键 一.Windows键 + 空格键“Space” [作用]:透明化所有窗口,快速查看桌面(并不切换) [快捷键]:win+空格 [小结]:当你打开了很多程序窗口的时候,这招非常有用 ...
- 怎样使我们的用户不再抵触填写Form表单?
转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 原文出处:https://blog.bitsrc.io/8-tips-for-an-awesome-sign ...
- 【转】线性插值(Linear Interpolation)基本原理
转:https://blog.csdn.net/u010312937/article/details/82055431 今天在阅读大牛代码的时候,发现了Linear Interpolation一次,百 ...
- 理解TCP/IP协议栈之HTTP2.0
1 前言 前面写了10多篇关于Redis底层实现.工程架构.实际应用的文章,感兴趣的读者可以进行阅读,如有问题欢迎交流: 1.Redis面试热点之底层实现篇-12.Redis面试热点之底层实现篇-23 ...
- 【转】Java 面试题问与答:编译时与运行时
在开发和设计的时候,我们需要考虑编译时,运行时以及构建时这三个概念.理解这几个概念可以更好地帮助你去了解一些基本的原理.下面是初学者晋级中级水平需要知道的一些问题. Q.下面的代码片段中,行A和行B所 ...
- vscode中nodejs智能提示
简单粗暴,直接在项目中,运行npm install --save-dev @types/node命令,然后就ok了.
- 沈阳网络赛 F - 上下界网络流
"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...
- 求1-n 中与 m 互质的素因子 (容斥原理)
ll prime[100]; ll cnt; void getprime(){ cnt = 0; ll num = m; for(ll i = 2; i*i <= m; i++){ // sqr ...
- Please verify that your device’s clock is properly set, and that your signing certificate is not expired.
解决方法: 1.关闭项目,找到项目文件XXXX.xcodeproj,在文件上点击右键,选择“显示包内容”(Show Package Contents).会新打开一个Finder. 2.在新打开的Fin ...
- Django CBV方法装饰器
from django.utils.decorators import method_decorator 1.在post 或 get方法 添加 @method_decorator(装饰器) 2.给类添 ...