정답 코드
#include <iostream>
#include <stack>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
string s;
cin>>n;
while(n--) {
string ans="YES";
cin>>s;
int len = s.size();
stack<int> stk;
for(int i=0; i<len; i++) {
if(s[i]=='(') {
stk.push(s[i]);
}
if(s[i]==')') {
if(stk.size()==0) {
ans="NO";
break;
}
stk.pop();
}
}
if(stk.size()) {
ans="NO";
}
cout<<ans<<'\n';
}
return 0;
}