-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path[BOJ] 1406 에디터.cpp
More file actions
68 lines (54 loc) · 1.25 KB
/
[BOJ] 1406 에디터.cpp
File metadata and controls
68 lines (54 loc) · 1.25 KB
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
67
68
#include <iostream>
#include <stack>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
string msg = "";
char cmd(16);
char word(16);
int count = 0;
stack<char> left, right;
cin >> msg;
cin >> count;
for (int i = 0; i < msg.length(); i++) {
left.push(msg[i]);
}
for (int i = 0; i < count; i++) {
cin >> cmd;
switch(cmd) {
case 'L' :
if(!left.empty()) {
right.push(left.top());
left.pop();
}
break;
case 'P' :
cin >> word;
left.push(word);
break;
case 'B' :
if(!left.empty()) {
left.pop();
}
break;
case 'D' :
if(!right.empty()) {
left.push(right.top());
right.pop();
}
break;
default:
break;
}
}
while(!left.empty()) {
right.push(left.top());
left.pop();
}
while(!right.empty()) {
cout << right.top();
right.pop();
}
cout << endl;
return 0;
}