| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:power string 2406 AC 不了,是为什么呢?In Reply To:power string 2406 AC Posted by:Lone_mover at 2008-07-14 09:13:30 我知道只要算出字符串的失效函数就可以了,
循环字节的长度 等于 字符串的长度 减去 最后一位的失效函数
但是我的代码为什么总是RTE呢?大牛指教了
我的代码:
#include <iostream>
#include <cstring>
using namespace std;
int next[10000];
char str[10000];
void get_next( int len)
{
int i = 1;
int j = 0;
next[1] = 0;
while(i<=len)
{
if(j == 0||str[i] == str[j])
{
i++;
j++;
next[i] = j;
}
else
j = next[j];
}
}
int main()
{
//vector<int> next(100);
int len;
int i;
while(scanf("%s", str)&&strcmp(str, ".")!=0)
{
len = strlen(str);
get_next( len);
for(i = 1;i<=len;++i)
cout<<next[i]<<" ";
cout<<endl;
cout<<len/(len - next[len])<<endl;
}
return 0;
}
感激不尽
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator