백준
[9012] 괄호
Jcoder
2018. 7. 22. 13:44
#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";elsecout << "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();elsereturn false;}}return st.empty();}