Chinaunix首页 | 论坛 | 博客
  • 博客访问: 33884
  • 博文数量: 22
  • 博客积分: 301
  • 博客等级: 二等列兵
  • 技术积分: 250
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-12 15:30
文章分类

全部博文(22)

文章存档

2019年(4)

2014年(1)

2013年(7)

2011年(8)

2010年(2)

TI

分类: C/C++

2019-03-09 11:49:12

bool CountSubStr(char * pShortString, char * pLongString)
{
/*在这里实现功能*/
int lens,lenl,i,j,cmpcount = 0;
if(NULL == pShortString && NULL == pLongString)
{
return false;
}


lens = (int)strlen(pShortString);
lenl = (int)strlen(pLongString);
if(0 == lens||0 == lenl)
{
return false;
}


for(j = 0; j < lenl; ++j)
{
    for(i = 0; i < lens; ++i)
    {
   
        if (*(pShortString+i) != '?')
        {
            if(*(pShortString+i) == *(pLongString+j))
            {
            cmpcount++;
            }
            else
            {
            i=0;
            break;
            }
        }
        else 
        {
            if(*(pShortString+i+1) == *(pLongString+j+1))
            {
                cmpcount++;
            }
            
            else if(*(pShortString+i+1) == *(pLongString+j+2))
                {
                cmpcount++;
                cmpcount++;
            }
            
            else if(*(pShortString+i+1) == *(pLongString+j+3))
            {
                cmpcount++;
                cmpcount++;
                cmpcount++;
            }
            else
            {
            i=0;
            break;
            }
        
        }
    }
}


if(cmpcount < lens)
    {
    return -1;
    }
else
    return cmpcount;
}




阅读(339) | 评论(0) | 转发(0) |
0

上一篇:练习题2

下一篇:没有了

给主人留下些什么吧!~~