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

我没有找到什么特殊用例...WA 。。。。n*n*n*n次

Posted by 0912190006 at 2010-01-16 12:04:19 on Problem 3753
#include <stdio.h>
#include <string.h>
int next[256];
int SafeStrcpy2KeyWord(char* pDestBuffer,
					   char* pSourceString,
					   int nDestBufferSize,
					   char* szKeyWord)
{
	if(strcmp(szKeyWord,"NULL")==0)
	{
		strcpy(pDestBuffer,"NULL");
		return 0;
	}
	int length_t=strlen(szKeyWord);
	int j=2;
	next[1]=1;
	if(length_t>=2)
	{
		while(j<length_t)
		{
			int k=j-1;
			while(k>0)
			{
				int n=0;
				for(;n<k;n++)
				{
					if(szKeyWord[n]!=szKeyWord[j-k+n])
						break;
				}
				if(n==k)
					break;
				k--;
			}
			next[j]=k+1;
			j++;
		}
	}
	j=0;
	int k=0;
	int length_s=strlen(pSourceString);
	while(j<length_s)
	{
		if(pSourceString[j]==szKeyWord[k])
		{
			j++;
			k++;
		}
		else
		{
			if(k==0)
				j++;
			else
				k=next[k]-1;

		}
		if(k==length_t)
			break;
	}
	int i,length=j+1-k;
	if(j+1-k>nDestBufferSize)
	{
		for (i=0;i<length-1;i++)
		{
			pDestBuffer[i]=pSourceString[i];
		}
		pDestBuffer[i]='\0';
		return 0;	
	}
	if(length==1)
	{
		strcpy(pDestBuffer,"NULL");
		return 0;
	}
	if(j==length_s&&k!=length_t)
	{
		strcpy(pDestBuffer,pSourceString);
		return length_s;
	}
	for (i=0;i<length-1;i++)
	{
		pDestBuffer[i]=pSourceString[i];
	}
	pDestBuffer[i]='\0';
	return length-1;
}
int main()
{
	char t[16],s[256],destStr[256];
	int i=1,destLength;
	gets(s);
	while(gets(t)&&strcmp(t,"END")!=0)
	{
		
		destLength=SafeStrcpy2KeyWord(destStr,s,255,t);
		printf("%d %s\n",destLength,destStr);
		i++;
	}
	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