| ||||||||||
| 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:Re:power string 2406 AC 不了,是为什么呢? Posted by:Lone_mover at 2008-07-14 09:15:52 > 我知道只要算出字符串的失效函数就可以了,
> 循环字节的长度 等于 字符串的长度 减去 最后一位的失效函数
> 但是我的代码为什么总是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;
> }
>
> 感激不尽
难道是失效函数算错了?不会啊,测试的例子是对的,
不过我自己写了一个这样的例子,xixix 照理说应该结果是一吧,可是它结果是2,就算是这样,也是WA,怎么会是RTE呢?
大牛,期待你的出现。
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator