Code: Judge consecutive and repeated characters in a string
String operation:
Int consecutiveCharMaxCount (char * str)
{
Char * pstr = NULL;
Char * p = NULL;
Int value = 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 = 0;
While (* pstr! = '\ 0 ')
{
Chrp = * pstr;
Chrn = * (++ pstr );
Value = chrp-chrn;
If (value = 1)
IncN ++;
Else
{
MaxCount = (maxCount> = incN )? MaxCount: incN;
IncN = 1;
}
If (value =-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;
}