#include<bits/stdc++.h>
using namespace std;
#define MAX 2000100
typedef long long ll;
int main()
{
/* #ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif*/
//double start_time = clock();
int t;
cin >> t;
while(t--){
string s;
cin >> s;
int n = s.size();
int cnt = 0, mx = 0;
stack<char>st;
char last;
while(!st.empty())st.pop();
int flag = 0;
for(int i = 0; i < n; i++){
if(s[i] == '('){
if(flag == 0){
cnt = 0;
while(st.size())st.pop();
}
flag = 1;
st.push('(');
}
else{
if(st.size() == 0)continue;
if(st.top() == '('){
cnt += 2;
flag = 0;
mx = max(cnt, mx);
st.pop();
if(st.size() == 0)cnt = 0;
}
else{
cnt = 0;
while(st.size())st.pop();
}
}
}
cout << mx << endl;
}
//double end_time = clock();
//printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
return 0;
}
No comments:
Post a Comment