난 정말 최고야 멋있어
[BOJ] 괄호 본문
#include <iostream>
#include <string>
#include <stack>
using namespace std;
void checkVPS(string& ps)
{
stack<int> s;
for (auto& i : ps)
{
if (i == '(')
s.push(0);
if (i == ')')
{
if (s.empty())
{
cout << "NO" << endl;
return;
}
s.pop();
}
}
if (s.empty())
cout << "YES" << endl;
else
cout << "NO" << endl;
}
int main()
{
int T;
string PS;
cin >> T;
for (int i = 0; i < T; i++)
{
cin >> PS;
checkVPS(PS);
}
}