//找出01字符串中0和1连续出现的最大次数
#include <stdio.h>
void Count(char *str, int *max0, int *max1)
{
int temp0 = 0;
int temp1 = 0;
while (*str++)
{
if (*str == '0')
{
temp0++;
if (*(str+1) == '1')
{
if (temp0 >*max0)
*max0 = temp0;
temp0=0; // remember reset 0
}
}
else if (*str == '1')
{
temp1++;
if (*(str+1) == '0')
{
if (temp1>*max1)
*max1 = temp1;
temp1=0; // remember reset 0
}
}
}
}
int main()
{
char *s = "0010101111100011000000110011";
int max0 = 0;
int max1 = 0;
Count(s, &max0, &max1);
printf("max0:%d\nmax1:%d\n", max0, max1);
return 0;
}
找出01字符串中0和1连续出现的最大次数
最新推荐文章于 2020-09-23 15:50:24 发布