-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1406 에디터.cpp
70 lines (59 loc) · 801 Bytes
/
1406 에디터.cpp
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()
{
stack<char> left;
stack<char> right;
string str;
int num;
cin >> str;
cin >> num;
for (int i = 0; i < str.length(); i++)
{
left.push(str[i]);
}
while (num--)
{
char cmd;
cin >> cmd;
switch (cmd)
{
case 'L':
if (!left.empty())
{
right.push(left.top());
left.pop();
}
break;
case 'D':
if (!right.empty())
{
left.push(right.top());
right.pop();
}
break;
case 'B':
if (!left.empty())
left.pop();
break;
case 'P':
char c;
cin >> c;
left.push(c);
break;
}
}
while (!left.empty())
{
right.push(left.top());
left.pop();
}
while (!right.empty())
{
printf("%c", right.top());
right.pop();
}
return 0;
}