POJ 3753 第一届顶嵌杯决赛 A题

//7915734    vrs570540852    3753    Accepted    368K    0MS    GCC    1169B    2010-11-23 18:36:18
//POJ 3753 第一届顶嵌杯决赛 A题
#include<stdio.h>
#include<string.h>

 

#define NULL 0

int SafeStrcpy2KeyWord(char* pDestBuffer,
                                   const char* pSourceString,   
                                   int nDestBufferSize,   
                                   char* szKeyWord)
{
    if(pDestBuffer==NULL || pSourceString==NULL)
        return 0;
    char *sourceSta=(char*)pSourceString;
    char *keySta=szKeyWord;
    char *destSta=pDestBuffer;
    int count=0;
    int keylen;
    if(keySta==0)
        keylen=0;
    else
        keylen=strlen(keySta);

    while(*sourceSta!='\0' && count<=nDestBufferSize)
    {
        if(count+keylen<=nDestBufferSize && keylen!=0 && !strncmp(sourceSta,keySta,keylen))
            return count;
        *destSta++=*sourceSta++;
        count++;
    }
    return count;
}

int main()
{
    char ptrDest[300]={0};
    char ptrSource[300]={0};
    char key[20]={0};
    int count;

    while(scanf("%s",&ptrSource)!=EOF)
    {
        while(scanf("%s",&key) && strcmp(key,"END\0"))
        {
            memset(ptrDest,0,sizeof(ptrDest));
            if(!strcmp(key,"NULL\0"))
            {
                printf("0 NULL\n");
                continue;
            }
            count=SafeStrcpy2KeyWord(ptrDest,ptrSource,260,key);
            if(count==0)
                printf("0 NULL\n");
            else
                printf("%d %s\n",count,ptrDest);
        }
    }
    return 0;
}

转载于:https://www.cnblogs.com/VRS_technology/archive/2010/11/23/1885772.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值