找出01数组中的0&&1连续的最大次数
#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;
}
相关推荐
SQL Server 2008 R2——查找最小nIndex,nIndex存在而nIndex+1不存在 求最小连续数组中的最大值
其实大家稍微动下大脑,问题可以转化为,是求最小连续数组中的最大值,数组大小可以为1。 ======================================================================= 做戏做全套,送佛送到西。 为了便于学习研究,必然是要写全套示例代码的。 ------------------------------------------------------------------------------------- --by wls --非专业SQL 不求高效 但求能跑 USE tempdb GO ---------------
leetcode1004-MaxConsecutiveOnesIII-Leetcode-1004:一种使用滑动窗口方法来查找最大子数组的算法,
leetcode 1004 MaxConsecutiveOnesIII-Leetcode-1004 Leetcode 问题 1004(中) 问题中使用的技术:滑动窗口
C# 如何判断一个Byte数组中是否存在某些连续的数据).txt
C# 如何判断一个Byte数组中是否存在某些连续的数据).txtC# 如何判断一个Byte数组中是否存在某些连续的数据).txtC# 如何判断一个Byte数组中是否存在某些连续的数据).txt
01背包问题_01背包问题_
课程作业,实现算法实践书后的例题,实现01背包问题
字符串中找出连续最长的数字字符串的实例代码
介绍了字符串中找出连续最长的数字字符串的实例代码,有需要的朋友可以参考一下


