Match:Seek the Name, Seek the Fame(POJ 2752)

               Match:Seek the Name, Seek the Fame(POJ 2752)

                追名逐利

  题目大意:给定一个字符串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)

上一篇:android学习日记13--数据存储之ContentProvide


下一篇:【转】深入理解 Session 与 Cookie