-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path210508.cpp
More file actions
86 lines (73 loc) · 1.44 KB
/
Copy path210508.cpp
File metadata and controls
86 lines (73 loc) · 1.44 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <vector>
using namespace std;
typedef struct node{
struct node* previous;
struct node* next;
int n;
bool exist;
}node;
node* A[1000000];
int N;
int k;
node* now;
vector<string> cmd;
vector<int> stack;
int main(){
cin >> N;
for(int i=0; i<N; i++){
A[i]->n = i;
A[i]->exist = true;
}
for(int i=0; i<N-1; i++){
A[i]->next = A[i+1];
}
for(int i=1; i<N; i++){
A[i]->previous = A[i-1];
}
A[0]->previous = A[N-1];
A[N-1]->next = A[0];
cin >> k;
now = A[k];
for(string c:cmd){
if(c[0] == 'U'){
int x = atoi(c.substr(2, c.length()-2).c_str());
while(x>0){
now = now -> previous;
x--;
}
}
else if(c[0] == 'D'){
int x = atoi(c.substr(2, c.length()-2).c_str());
while(x>0){
now = now->next;
x--;
}
}
else if(c[0] == 'C'){
now->exist = false;
node* tmp = now->previous;
tmp->next = now->next;
node* tmp2 = now->next;
tmp2->previous = now->previous;
stack.push_back(now->n);
if(now->n < now->next->n)
now = now->next;
else
now = now->previous;
}
else if(c[0] == 'Z'){
int a = stack.back();
stack.pop_back();
A[a]->exist = true;
A[a]->previous->next = A[a];
A[a]->next->previous = A[a];
}
}
string ans = "";
for(int i=0; i<N; i++){
if(A[i]->exist) ans += "O";
else ans += "X";
}
return 0;
}