파싱
회전하는 큐에 파싱과정이 추가됨.
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
int main() {
int T;
cin >> T;
string arr;
while (T--) {
bool forward = true;
string cmd;
deque <int> dq;
int n;
cin >> cmd;
cin >> n;
cin >> arr;
arr = arr.substr(1, arr.size() - 2);
stringstream ss(arr);
string token;
while (getline(ss, token, ',')) {
dq.push_back(stoi(token));
}
bool error = false;
for (char c : cmd) {
if (c == 'R')
forward = !forward;
else {
if (dq.empty()) {
error = true;
break;
}
if (forward) {
dq.pop_front();
}
else {
dq.pop_back();
}
}
}
if (error) {
cout << "error" << "\n";
}
else {
if (!forward)
reverse(dq.begin(), dq.end());
cout << "[";
while (!dq.empty()) {
cout << dq.front();
dq.pop_front();
if (dq.size())
cout << ",";
}
cout << "]\n";
}
}
}