追名逐利

  题目大意:给定一个字符串S,要你找到S的所有前缀后缀数组

  还是Kmp的Next数组的简单应用,但是这一题有一个BUG,那就是必须输出字符串的长度(不输出就WA),然而事实上对于abcbab,这样输出会是2,6,很明显是错,但是答案还是会判对,吃惊

  

 #include <iostream>
#include <algorithm>
#include <functional>
#include <string.h> using namespace std; static char str[];
static int _Next[], store[]; void Get_Next(const int); int main(void)
{
int Length, store_len;
while (~scanf("%s", str))
{
Length = strlen(str);
Get_Next(Length);
store_len = ; //if (_Next[Length] >= Length / 2)
// store[store_len++] = Length;
store[store_len++] = Length;
for (int k = _Next[Length]; k > ; k = _Next[k])
store[store_len++] = k;
for (int i = store_len - ; i >= ; i--)
printf("%d ", store[i]);
printf("\n");
}
return EXIT_SUCCESS;
} void Get_Next(const int Length)
{
int i = , k = -;
_Next[] = -; while (i < Length)
{
if (k == - || str[i] == str[k])
{
i++;
k++;
_Next[i] = k;
}
else k = _Next[k];
}
}

  

Match:Seek the Name, Seek the Fame(POJ 2752)的更多相关文章

  1. Seek the Name, Seek the Fame POJ - 2752

    Seek the Name, Seek the Fame POJ - 2752 http://972169909-qq-com.iteye.com/blog/1071548 (kmp的next的简单应 ...

  2. (KMP)Seek the Name, Seek the Fame -- poj --2752

    http://poj.org/problem?id=2752 Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536 ...

  3. Seek the Name, Seek the Fame - POJ 2752(next运用)

    题目大意:小猫是非常有名气的,所以很多父母都来找它给孩子取名字,因为找的人比较多,小猫为了摆脱这个无聊的工作,于是它发明了一种取名字的办法,它把孩子父母的名字合在一起,然后从这个名字里面找一个前缀,并 ...

  4. Seek the Name, Seek the Fame POJ - 2752(拓展kmp || kmp)

    题意: 就是求前缀和后缀相同的那个子串的长度  然后从小到大输出 解析: emm...网上都用kmp...我..用拓展kmp做的  这就是拓展kmp板题嘛... 求出extend数组后  把exten ...

  5. POJ 2752 Seek the Name, Seek the Fame [kmp]

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Ac ...

  6. poj 2752 Seek the Name, Seek the Fame(KMP需转换下思想)

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10204   Ac ...

  7. KMP + 求相等前后缀--- POJ Seek the Name, Seek the Fame

    Seek the Name, Seek the Fame Problem's Link: http://poj.org/problem?id=2752 Mean: 给你一个字符串,求这个字符串中有多少 ...

  8. KMP POJ 2752 Seek the Name, Seek the Fame

    题目传送门 /* 题意:求出一个串的前缀与后缀相同的字串的长度 KMP:nex[]就有这样的性质,倒过来输出就行了 */ /************************************** ...

  9. poj 2752 Seek the Name, Seek the Fame【KMP算法分析记录】【求前后缀相同的子串的长度】

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14106   Ac ...

随机推荐

  1. typecho除了首页其他大部分网页404怎么办?

    server { listen ; server_name blog.localhost; #绑定域名 index index.htm index.html index.php; #默认文件 root ...

  2. ubuntu 14.04 安装mysql server的分支MariaDB Server初级教程

    序,MariaDB Server是Mysql的fork版本,与Mysql完美兼容,mysql在10年被sun收购,后sun被oracle收购,后mysql的创建者及项目长期技术带头人之一的Michae ...

  3. pyspider安装

    官方文档上说的比较简单: pip install pyspider 但是实际安装时还是有些问题导致无法成功. windows下安装 先安装PhantomJS 可以依照自己的开发平台选择不同的包进行下载 ...

  4. Linux(Red Hat)-中安装Vmware Tools

    0. 会弹出 ***1.在弹出的文件夹中找到"VMwwareTools9.6.2-1688356.tar.gz",右击"解压缩到"...我解压缩到了" ...

  5. JAVA 如何使JScrollPane中的JTextArea自动滚动到最后一行?

    1.要使JTextArea带有滚动条,需将JTextArea对象添加到JScrollPane中. JTextArea logArea = new JTextArea(15, 35); //创建JTex ...

  6. vim 编辑器的设置

    vi编辑器的配置:http://blog.mcuol.com/User/fenghua/Article/17411_1.htm ******************************vim ~/ ...

  7. iOS开发——UI进阶篇(十二)事件处理,触摸事件,UITouch,UIEvent,响应者链条,手势识别

    触摸事件 在用户使用app过程中,会产生各种各样的事件 一.iOS中的事件可以分为3大类型 触摸事件加速计事件远程控制事件 响应者对象在iOS中不是任何对象都能处理事件,只有继承了UIResponde ...

  8. leetcode 236. Lowest Common Ancestor of a Binary Tree

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...

  9. leetcode 215. Kth Largest Element in an Array

    Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...

  10. git 教程(7)--撤销修改

    自然,你是不会犯错的.不过现在是凌晨两点,你正在赶一份工作报告,你在readme.txt中添加了一行: