| //https://www.acmicpc.net/problem/9012 #include <iostream> | |
| #include <stack> | |
| #include <string> | |
| using namespace std; | |
| bool vps(){ | |
| stack<char> s; | |
| string str; | |
| cin >>str; | |
| int l=str.size(); | |
| s.push(str[0]); | |
| for(int i=1; i<l; i++){ | |
| if(str[i]==')'){ | |
| if(!s.empty()){ | |
| if(s.top()=='(') | |
| s.pop(); | |
| } | |
| else s.push(str[i]); | |
| } | |
| else s.push(str[i]); | |
| } | |
| if(s.empty()) return true; | |
| else return false; | |
| } | |
| int main(){ | |
| int tc; | |
| cin >> tc; | |
| for(int i=0; i<tc; i++){ | |
| if(vps()) cout << "YES\n"; | |
| else cout <<"NO\n"; | |
| } | |
| return 0; | |
| } |
'알고리즘 문제 풀이 > 1DP_과제(~180615)' 카테고리의 다른 글
| 180523_10610_30 (0) | 2018.05.23 |
|---|---|
| 180522_4963_섬의 개수 (0) | 2018.05.22 |
| 180519_9461_파도반 수열 (0) | 2018.05.19 |
| 180518_4597_패리티 (0) | 2018.05.18 |
| 180518_14623_감정이입 (0) | 2018.05.18 |