题目要求:
有一串字符串,其中 " () " 、“()()” 、“(())” 等符合括号规则的字符串,为真 括号字符串, 如 "(a)"、"(()"、“{ ]” 、等 不为真括号字符串,
现求给定一串字符串的 最长 括号字符串的 长度(测试用例有多组)
input:
(())(((123)))
output:
4
代码:
// 本题为考试单行多行输入输出规范示例,无需提交,不计分。
#include <iostream>
#include <string>
using namespace std;
int longll(string str)//返回从第一个开始的字符 的 () 长度
{
char P = '(' , Q = ')';
int px=0,pl=0;
int len = str.length();
for(int i = 0; i<len;i++)
{
if(str.at(i) == P)
{
pl++;
px++;
}
else if(pl>0 && str.at(i)== Q)
{
pl--;
px++;
}
else if(pl==0&& str.at(i) != P && str.at(i)!= Q)
{
return px;
}
else if(pl!=0&& str.at(i) != P &&