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

我也来一个

Posted by lijinwu at 2010-04-07 14:53:19 on Problem 3753
In Reply To:我用string做的不知道厚道不厚道 Posted by:HIT_Happy at 2010-04-07 14:00:10
#include <iostream>
using namespace std;
int SafeStrcpy2KeyWord(char * pDestBuffer,char * pSourceString, int nDestBufferSize,char * szKeyWord)
{
	if(strcmp(szKeyWord,"END")==0)
	{
		return -2;
	}
	if(strcmp(szKeyWord,"NULL")==0)
	{
		return -1;
	}
	int lenkw=strlen(szKeyWord);

	for(int i=0;i<nDestBufferSize-lenkw+1;i++)
	{
		if(strncmp(pSourceString+i,szKeyWord,lenkw)==0)
		{
			strncpy(pDestBuffer,pSourceString,i);
			pDestBuffer[i]='\0';
			return i;
		}
	}
	strcpy(pDestBuffer,pSourceString);
	return nDestBufferSize;
}

int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);	
	char pDestBuffer[260],pSourceString[260],szKeyWord[20];
	while(scanf("%s",pSourceString)!=EOF)
	{
		int lens=strlen(pSourceString);
		while(true)
		{
			scanf("%s",szKeyWord);
			int lend=SafeStrcpy2KeyWord(pDestBuffer,pSourceString,lens,szKeyWord);
			if(lend==-1)
			{
				printf("0 NULL\n");
			}
			else if(lend==-2)
			{
				break;
			}
			else if(lend==0)
			{
				printf("0 NULL\n");
			}
			else
			{
				printf("%d %s\n",lend,pDestBuffer);
			}
		}
	}
	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