用C/C++帮我写个函数,其功能是判断一个输入中至少要有两个1,在任何两个1之间有偶数个0

来源:百度知道 编辑:UC知道 时间:2024/06/01 03:09:22

//若满足条件,返回true,否则返回false
bool f(const char* str)
{

const char *p = str;
while(*p != '1') //忽略掉字符前面的'0'
{
p++;
}
p++;
while(*p != '\0')
{
int count = 0;
while((*p != '1')&&(*p != '\0')) //计算两个'1'之间'0'的个数

{

if(*p == '0')
{
count++;
}
p++;
}
if((!(count%2))&&(*p != '\0')) //若存在一个,返回
{
return true;
}
else
{
count = 0; //count置为0,继续循环
p++;
}

}
return false;
}