-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj1406.cpp
More file actions
70 lines (62 loc) · 1.24 KB
/
boj1406.cpp
File metadata and controls
70 lines (62 loc) · 1.24 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
69
70
#include <iostream>
#include <string>
#include <stack>
using namespace std;
int main()
{
int M;
string s = "";
stack<char> left;
stack<char> right;
cin >> s;
for (int i = 0; i < (int)s.size(); i++)
{
left.push(s[i]);
}
cin >> M;
for (int i = 0; i < M; i++)
{
char cmd, c;
cin >> cmd;
if (cmd == 'L')
{
if (!left.empty())
{
right.push(left.top());
left.pop();
}
}
else if (cmd == 'D')
{
if (!right.empty())
{
left.push(right.top());
right.pop();
}
}
else if (cmd == 'B')
{
if (!left.empty())
{
left.pop();
}
}
else if (cmd == 'P')
{
cin >> c;
left.push(c);
}
}
// left에 있는 원소들 모두 right로 이동!
while (!left.empty())
{
right.push(left.top());
left.pop();
}
// right에 있는 원소 출력
while (!right.empty())
{
cout << right.top();
right.pop();
}
}