找出01数组中的0&&1连续的最大次数

issac_gang issac_gang 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
如题,程序不报错,正常运行,但就是没结果。是没结果,黑屏。求解答

#include <iostream>
void calculate0and1();
using namespace std;

void calculate0and1( char *str,int *max0,int *max1)
{
int temp0 = 0;
int temp1 = 0;
while (*str)
{
if (*str ==' 0')
{
(*max0)++;
if (*(++str) == '1')
{
if (temp0 < *max0)
{
temp0 = *max0;
}
*max0 = 0;
}
}
else if (*str == '1')
{
(*max1)++;
if (*(++str) == '0')
{
if (temp1 < *max1)
{
temp1 = *max1;
}
*max1 = 0;
}
}
}
*max0 = temp0;
*max1 = temp1;
}
int main()
{
char string[] = "00001111001010101010101010001011101001010";
int max0 = 0;
int max1 = 0;
calculate0and1(string, &max0, &max1);
cout << max0 << max1 << endl;
return 0;
}
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
issac_gang
C++ 语言 65,212 成员 250,513 内容