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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <vector>
#include <string>
#include <stack>
 
using namespace std;
 
int main() {
    vector<bool> result;
 
    while (true) {
        string str;
        bool isValance = true;
        getline(cin, str, '\n');  //한줄씩 입력받기
 
        if (str == ".")  //점만 들어오면 그만
            break;
 
        stack<char> s;
 
        for (int i = 0; i < str.size(); i++) {
            char current = str.at(i);
 
            if (current == '(' || current == '[') {  //열린 괄호면 push
                s.push(current);
            }
 
            else if (current == ')') {
                if (s.empty() || s.top() == '[') {
                    //stack 비어있거나 짝 안맞는 괄호 들어오면
                    isValance = false;
                    break;
                }
                else
                    s.pop();
            }
 
            else if (current == ']') {
                if (s.empty() || s.top() == '(') {
                    //stack 비어있거나 짝 안맞는 괄호 들어오면
                    isValance = false;
                    break;
                }
                else
                    s.pop();
            }
 
            else  //괄호 아닌 다른 글자면
                continue;
 
        }
        if (!s.empty())  //열린 괄호 남아있는지 확인
            isValance = false;
 
        result.push_back(isValance);
    }
 
    for (int i = 0; i < result.size(); i++) {
        if (result[i])
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
 
    return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

 

 

'Baekjoon' 카테고리의 다른 글

[#18258] 큐 2  (0) 2020.03.15
[#1874] 스택 수열  (0) 2020.03.15
[#9012] 괄호  (0) 2020.03.15
[#10828] 스택  (0) 2020.03.15
[#1010] 다리 놓기  (0) 2020.03.14

+ Recent posts