-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1406.h
59 lines (53 loc) · 1.17 KB
/
1406.h
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
#include <iostream>
#include <queue>
using namespace std;
deque<char> D;
string str;
int M;
int main_1406() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> str;
int s = str.size();
for(int i=0;i<s;i++)
D.push_back(str[i]);
cin >> M;
D.push_front('.');
for(int i=0;i<M;i++){
char command;
cin >> command;
if(command =='L'){
if(D.back() != '.'){
D.push_front(D.back());
D.pop_back();
}
}else if(command == 'D'){
if(D.front() != '.'){
D.push_back(D.front());
D.pop_front();
}
}else if(command == 'B'){
if(D.back() != '.'){
D.pop_back();
}
}else if(command == 'P'){
char c;
cin >> c;
D.push_back(c);
}
}
s = D.size();
int cursorPos = -1;
for(int i=0;i<s;i++){
if(D[i] == '.'){
cursorPos = i;
break;
}
}
for(int i=cursorPos+1;i<s;i++)
cout << D[i];
for(int i = 0;i<cursorPos;i++)
cout << D[i];
cout << endl;
return 0;
}