-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAC.cpp
More file actions
78 lines (73 loc) · 1.89 KB
/
AC.cpp
File metadata and controls
78 lines (73 loc) · 1.89 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
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<deque>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, t;
cin >> t;
while (t--) {
string order, str;
bool reverse = false, error = false;
deque<int> dq;
cin >> order;
cin >> n;
cin >> str;
string s = "";
for (int i = 0; i < str.length(); i++) {
if (isdigit(str[i])) {
s += str[i];
}
else {
if (!s.empty()) {
dq.push_back(stoi(s));
s = "";
}
}
}
for (auto o : order) {
if (o == 'R') {
if (reverse)
reverse = false;
else
reverse = true;
}
else {
if (dq.empty()) {
cout << "error" << '\n';
error = true;
break;
}
if (reverse)
dq.pop_back();
else
dq.pop_front();
}
}
if (!error) {
cout << '[';
}
if (reverse && !dq.empty()) {
for (auto o = dq.rbegin(); o != dq.rend(); o++) {
if (o == dq.rend() - 1)
cout << *o;
else
cout << *o << ',';
}
}
else if (!reverse && !dq.empty()) {
for (auto o = dq.begin(); o != dq.end(); o++) {
if (o == dq.end() - 1)
cout << *o;
else
cout << *o << ',';
}
}
if (!error)
cout << "]\n";
}
}