Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:power string 2406 AC 不了,是为什么呢?

Posted by Lone_mover at 2008-07-14 09:15:52
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator