* Computer Science/Algorithm
baekjun 9012. 괄호
soicem
2018. 8. 22. 16:58
자료구조 선택의 중요성
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include <iostream> #include <string> #include <vector> using namespace std; string paren; int level; int main() { int cases; cin >> cases; while (cases--) { cin >> paren; vector<char> stk; for (int i = 0; i < paren.size(); i++) if (paren[i] == '(') stk.push_back('('); else { if (stk.size() > 0) stk.pop_back(); else { stk.push_back('e'); break; } } if (stk.size() == 0) cout << "YES\n"; else cout << "NO\n"; } //system("pause"); return 0; } | cs |