| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:哪位过的大神把代码贴出来瞧瞧。。。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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator