#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();}
'백준' 카테고리의 다른 글
[10845] 큐 (0) | 2018.07.22 |
---|---|
[2504] 괄호의 값 (0) | 2018.07.22 |
[10828] 스택 (0) | 2018.07.21 |
[4948] 베르트랑 공준 (0) | 2018.07.21 |
[1929] 소수 구하기 (0) | 2018.07.17 |