-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5430.cpp
More file actions
74 lines (67 loc) · 1.6 KB
/
Copy path5430.cpp
File metadata and controls
74 lines (67 loc) · 1.6 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
#include <bits/stdc++.h>
using namespace std;
int t;
string p;
int n;
string str;
deque<int> dq;
bool err;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> t;
while (t--) {
err = false;
bool rev = false;
cin >> p;
cin >> n;
cin >> str;
string temp;
for (int i = 0; i < str.size(); i++) {
if (str[i] == ',' || str[i] == ']') {
if (temp != ""){
dq.push_back(stoi(temp));
temp = "";
}
}
else if (isdigit(str[i])) {
temp += str[i];
}
}
for (int i = 0; i < p.size(); i++) {
if (p[i] == 'R') {
rev = rev ? false : true;
}
else {
if (dq.empty()) {
cout << "error\n";
err = true;
break;
}
if (!rev)
dq.pop_front();
else
dq.pop_back();
}
}
if (!err) {
cout << "[";
if (!rev) {
for (int i = 0; i < dq.size(); i++){
cout << dq[i];
if (i < dq.size() - 1) cout << ",";
}
}
else {
for (int i = dq.size() - 1; i >= 0; i--){
cout << dq[i];
if (i > 0) cout << ",";
}
}
cout << "]\n" ;
}
dq.clear();
}
return 0;
}