https://www.acmicpc.net/problem/5397


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
#include <iostream>
#include <cstring>
#include <string>
#include <stack>
 
#pragma warning (disable : 4996)
using namespace std;
 
int main() {
    int N;
    string input;
    stack<char> stack1, stack2;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> input;
        int size1 = input.size();
        for (int j = 0; j < size1; j++) {
            if (input[j] == '<') {
                if (stack1.empty() == 0){
                    char a;
                    a = stack1.top();
                    stack1.pop();
                    stack2.push(a);
                }
            }
            else if (input[j] == '>') {
                if (stack2.empty() == 0){
                    char a;
                    a = stack2.top();
                    stack2.pop();
                    stack1.push(a);
                }
            }
            else if (input[j] == '-') {
                if (stack1.empty() == 0)
                    stack1.pop();
            }
            else
                stack1.push(input[j]);
        }
 
        if (stack1.size() > 0){
            size1 = stack1.size();
            for (int j = 0; j < size1; j++) {
                char a;
                a = stack1.top();
                stack1.pop();
                stack2.push(a);
            }
        }
 
        int size = stack2.size();
        for (int j = 0; j < size; j++) {
            char a;
            a = stack2.top();
            stack2.pop();
            cout << a;
        }
 
        cout << endl;
    }
 
    return 0;
}
cs


+ Recent posts