String ------ find out the maximum number of consecutive occurrences of o and 1 in the 01 string

topic:

Idea:

  1. Record the maximum value in the traversal, compare it with temp, and exchange

Code:

Void Calculate(const char *str,int *max0,int *max1)
{
Int temp0=0; //Save the maximum length of 0 string
Int temp1=0; //Save the maximum length of 1 string

While(*str)
{
If(*str=='0')
{
(*max0)++; //0 length
If(*str++ == '1') //If the next one is 1
{
If(temp0<*max0) //Check if the current length needs to be saved
{
Temp0=*max0;
}
*max0=0;
}
}
Else if(*str=='1')
{
(*max1)++; //1 length
If(*str++ == '0') //If the next one is 1
{
If(temp1<*max1) //Check if the current length needs to be saved
{
Temp1=*max1;
}
*max1=0;
}
}
}
*max0=temp0;
*max1=temp1;
}