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

ms copy 严的那本书, 它的字符串下标从1开始

Posted by reload at 2006-01-24 15:53:52 on Problem 2752
In Reply To:必胜客在召唤^_^ Posted by:outstanding at 2006-01-23 22:13:14
> 我很努力地学习和使用KMP函数,为什么从TLE到WA就是不AC捏?
> 这样吧,谁能教我AC我请他吃必胜客好吗?
> #include <iostream>
> #include <string>
> using namespace std;
> string s;
> char c;
> int next[400002],len, ans[400002];
> 
> void get_next()
> {
> 
> 	int i, j;		 
> 	i = 0; 
> 	j = -1;
> 	next[0] = -1;
> 	next[1] = 0;
> 	while(i <= len)
> 	{
> 		if(j == -1 || s[i] == s[j])
> 		{
> 			j++; 
> 			i++; 
> 			next[i] = j;
> 		}
>         else j=next[j];
> 	}
> 
> }
> 
> 
> int main()
> {
> 	int i, j;
> 	s = "";
> 	while(scanf("%c", &c) != EOF)
> 	{
> 		if(c != '\n')
> 		{
> 			s += c;
> 		}
> 		else
> 		{	len = s.size();
> 			memset(next, 0, sizeof(next));
> 			get_next();
> 			i = 0;
> 			while(len)
> 			{
> 				ans[i++] = len;
> 				len = next[len];
> 			}
> 			for(j= i-1; j >= 0; j--)
> 			{
> 				if(j != i-1)
> 					printf(" ");
> 				printf("%d", ans[j]);
> 			}
> 			printf("\n");
> 			s = "";
> 		}
> 	}
> 	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