#include<bits/stdc++.h>
using namespace std;
int main()
{
string a;
stack<int>s;
int T;
cin>>T;
while(T--)
{
s.push(-1);
cin>>a;
int len = a.size();
s.push(0);
for(int i=1;i<len;i++)
{
if(a[s.top()]=='('&&a[i]==')') s.pop();
else s.push(i);
}
int flag = len;
int tmp;
int mm = -1;
while(!s.empty())
{
tmp = s.top();
s.pop();
mm = max(mm,abs(tmp-flag));
flag=tmp;
}
cout<<mm-1<<endl;
}
return 0;
}
喵哈哈村的括号序列(初学栈)
最新推荐文章于 2023-11-08 00:36:08 发布
