首页 > 代码库 > 代码:字符串中连续与重复字符判断
代码:字符串中连续与重复字符判断
字符串操作:
int consecutiveCharMaxCount( char *str)
{
char *pstr = NULL;
char *p = NULL;
int value = http://www.mamicode.com/0;
int incN = 1;
int decN = 1;
int maxCount = 0;
char chrp = 0;
char chrn = 0;
if(str == NULL)
return ERROR;
p = str;
while(*p != ‘\0‘)
{
pstr = p;
incN = 1;
decN =1;
value = http://www.mamicode.com/0;
while(*pstr != ‘\0‘)
{
chrp = *pstr;
chrn = *(++pstr);
value = http://www.mamicode.com/chrp - chrn;
if(value =http://www.mamicode.com/= 1)
incN++;
else
{
maxCount = (maxCount>=incN)?maxCount:incN;
incN = 1;
}
if(value =http://www.mamicode.com/= -1)
decN++;
else
{
maxCount = (maxCount>=decN)?maxCount:decN;
decN = 1;
}
}
p++;
}
return maxCount;
}
int repeatedCharMaxCount( char *str)
{
char pchar[2] = {0};
char *pindex = NULL;
char *pstr = NULL;
int n = 0;
int maxCount = 0;
if(str == NULL)
return ERROR;
pstr = str;
while(*pstr != ‘\0‘)
{
memset(pchar,0,2);
pchar[0] = *pstr;
pindex = index(pstr,pchar[0]);
n = strspn(pindex,pchar);
maxCount = (maxCount>=n)?maxCount:n;
pstr++;
}
return maxCount;
}
代码:字符串中连续与重复字符判断
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。