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 Zerlier at 2010-01-16 12:30:23 on Problem 3753
In Reply To:Re:哪位过的大神把代码贴出来瞧瞧。。。 Posted by:0911180012 at 2010-01-16 12:27:39
#include <stdio.h>
#include <string.h>

int SafeStrcpy2KeyWord(char* pDestBuffer,       //源字符串
                       char* pSourceString,     //目的字符串
                       int nDestBufferSize,     //缓冲区长度
                       char* szKeyWord) //指定键字符串
{
        int i;
        int lenKW;

	if ( strcmp( szKeyWord, "NULL" ) == 0 )
	{
		return -1;
	}
	if ( strcmp( szKeyWord, "END" ) == 0 )
        {
                return -2;
        }

        lenKW = strlen( szKeyWord );

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

	strcpy( pSourceString, pDestBuffer );
	
        return nDestBufferSize;
}

int main()
{
        char dec[260];
        char out[260];
        char keyWord[20];
        int lenDec;
        int lenOut;
	
	while ( scanf( "%s", lenDec ) != EOF)
	{
		lenDec = strlen(dec);

		while (1)
		{
			gets( keyWord );
		
			lenOut = SafeStrcpy2KeyWord( dec, out, lenDec, keyWord );
			if ( lenOut == -2 )
			{
				break;
			}
			else if ( lenOut == -1 )
			{
				printf( "0 NULL\n" );
			}
			else
			{
				printf( "%d ", lenOut );
				if ( lenOut == 0 )
				{
					puts("NULL");
				}
				else
				{
					puts(out);	
				}
			}
		}
        }
        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