-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5430)AC.cpp
More file actions
91 lines (78 loc) · 1.43 KB
/
5430)AC.cpp
File metadata and controls
91 lines (78 loc) · 1.43 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
87
88
89
90
91
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int testCase;
int arrSize;
int arrBegin = 0;
int arrEnd;
int i, j, k;
string function;
string arrString;
vector<int> arr;
bool errflag = false;
bool isReversed = false;
cin >> testCase;
for (i = 0; i < testCase; i++) {
cin >> function;
cin >> arrSize;
cin >> arrString;
arrEnd = arrSize - 1;
for (j = 1; j < arrString.length(); j++) {
if (arrString[j] >= '0' && arrString[j] <= '9') {
k = j;
while (arrString[k] >= '0' && arrString[k] <= '9')
k++;
arr.push_back(stoi(arrString.substr(j, k - j)));
j = k - 1;
}
}
for (j = 0; j < function.length(); j++) {
if (function[j] == 'R') {
isReversed = !isReversed;
}
else {
if (arrSize == 0) {
errflag = true;
break;
}
if (isReversed) {
arrEnd--;
}
else {
arrBegin++;
}
arrSize--;
}
}
if (errflag) {
cout << "error\n";
}
else {
cout << '[';
if (isReversed) {
for (j = arrEnd; j >= arrBegin; j--) {
cout << arr[j];
if (j != arrBegin)
cout << ',';
}
}
else {
for (j = arrBegin; j <= arrEnd; j++) {
cout << arr[j];
if (j != arrEnd)
cout << ',';
}
}
cout << "]\n";
}
isReversed = false;
errflag = false;
arrBegin = 0;
arr.clear();
}
}