백준
[9012] 괄호
by Jcoder
2018. 7. 22.
#include <iostream>
#include <stack>
#include <string>
using namespace std;
bool checkVPS(string str);
int main()
{
string str;
int testcase;
cin >> testcase;
for (int i = 0; i < testcase; i++)
{
cin >> str;
if (checkVPS(str))
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
bool checkVPS(string str)
{
stack <char> st;
for (int i = 0; i < str.length(); i++)
{
char c = str[i];
if (c == '(')
{
st.push(str[i]);
}
else
{
if (!st.empty())
st.pop();
else
return false;
}
}
return st.empty();
}