Algorithm/C++ - BOJ

BOJ/백준 - 9012 괄호 C++

ㅇㅇ잉 2021. 2. 18. 15:13
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
34
35
36
37
38
39
40
#include <iostream>
#include <stack>
using namespace std;
 
int main(void) {
    cout.tie(NULL);
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
 
    int T;
    stack <char> s;
    
    cin >> T;
 
    while (T--) {
        string tmp;
        cin >> tmp;
        bool check = true;
        for (int i = 0; i < tmp.length(); i++) {
            if (')' == tmp[i]) {
                if (!s.empty()) {
                    s.pop();
                }
                else {
                    check = falsebreak;
                }
            }
            else s.push(tmp[i]);
        }
 
        if (check && s.empty()) cout << "YES\n";
        else cout << "NO\n"
        
 
        while (!s.empty()) s.pop();
    }
 
 
    return 0;
}
cs