티스토리 뷰

algorithm'''problem solve

[백준]5430-AC(설명X)

JunHwa Park 2020. 2. 3. 03:26
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
#include <iostream>
#include <queue>
using namespace std;
 
int main()
{
    int T;
    cin >> T;
    for (size_t i = 0; i < T; i++) {
        string command, element;
        int n;
        cin >> command >> n >> element;
        string tmp;
        deque<string> deq;
        for (size_t j = 0; j < element.size(); j++) {
            if (element[j] == '[');
            else if (element[j] == ',' || element[j] == ']') {
                if (tmp.size() > 0)
                    deq.push_back(tmp);
                tmp.clear();
            }
            else {
                tmp.append(1, element[j]);
            }
        }
        bool order = true, error = false;
        for (size_t j = 0; j < command.size(); j++) {
            if (command[j] == 'R')
                order = !order;
            else {
                if (deq.size() == 0) {
                    error = true;
                    break;
                }
                else if (order)
                    deq.pop_front();
                else
                    deq.pop_back();
            }
        }
        if (error)
            cout << "error" << endl;
        else {
            cout << '[';
            while (deq.size() > 0) {
                if (order) {
                    cout << deq.front();
                    deq.pop_front();
                    if (deq.size() > 0)
                        cout << ',';
                }
                else {
                    cout << deq.back();
                    deq.pop_back();
                    if (deq.size() > 0)
                        cout << ',';
                }
            }
            cout << ']' << endl;
        }
    }
    return 0;
}
cs
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/12   »
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
글 보관함