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:哪位过的大神把代码贴出来瞧瞧。。。

Posted by D10001252 at 2010-11-24 14:28:44 on Problem 3753
In Reply To:哪位过的大神把代码贴出来瞧瞧。。。 Posted by:0911180012 at 2010-01-16 12:21:38
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int SafeStrcpy2KeyWord(char* pDestBuffer,	//拷贝的目的地地址
		       char* pSourceString,	//拷贝的源地址
		       int nDestBufferSize,	//拷贝的目的地缓冲区长度
		       char* szKeyWord)		//指定关键字符串
{
	int len;
	if(strlen(szKeyWord)==0)len=strlen(pSourceString);
	else 
	{
		char *end =strstr(pSourceString,szKeyWord); 
		if(end==0)len=strlen(pSourceString);
		else len = end - pSourceString;	
	}
	memset(pDestBuffer,0,nDestBufferSize);
	memcpy(pDestBuffer,pSourceString,len);
	return len;
}

int main()
{
	char src[256],keyword[256],dest[256];
	while(scanf("%s",src)!=EOF)
	{
		while((scanf("%s",keyword))!=EOF)
		{
			int len;
			if(strcmp(keyword,"END")==0)break;
			else if(strcmp(keyword,"NULL")==0)
			{
				len= 0;
			}
			else
				len= SafeStrcpy2KeyWord(dest,src,256,keyword);	
			printf("%d ",len);
			if(len==0)
			{
				printf("NULL\n");
			}
			else printf("%s\n",dest);
		}
		memset(src,0,256);
	}
	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