#28053: CPP


11030067@mail.hpsh.tp.edu.tw (和平110級鄧雨珊)

學校 : 臺北市立和平高級中學
編號 : 163096
來源 : [61.64.210.174]
最後登入時間 :
2022-10-23 16:54:59
b838. 104北二2.括號問題 -- 104北二區桃竹苗基資訊學科能力複賽 | From: [219.85.43.159] | 發表日期 : 2021-11-11 23:14

#include <iostream>
using namespace std;

int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t;
string str;
cin >> t;
while (t--){
cin >> str;
int p=0, ans=0;
for (int i=0; i<str.length(); i++){
if (str[i]=='('){
p++;
}
else {
p--;
ans++;
}
if (p<0){
break;
}
}
if (!p){
cout << ans <<endl;
}
else {
cout <<"0\n";
}
}
}
 
ZeroJudge Forum