输入一个字符串,检查里面的左右括号是否匹配
bool pipeikuohao(const char* str,int length)
{
if (str == nullptr || length <= 1)
return false;
int a = 0;
int left = 0;
int right = 0;
bool findfirstright = false;
while (a < length)
{
if (str[a] == '(' || str[a] == ')')
{
if (str[a] == '(')
++left;
else if (str[a] == ')' && left > right)
++right;
else
return false;
}
++a;
}
if (left != right)
return false;
return true;
}