#include <iostream>
#include <string>
#include <deque>
#include <algorithm>

using namespace std;
int n;
// [1,2,3,4] 이렇게 출력
void print_res(deque<int> &q) {
    cout << '[';
    for(int i=0; i<q.size(); i++) {
        cout << q[i];
        if(i+1 != q.size()) cout << ',';
    }
    cout << "]\n";
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n;

    while(n--) {
        //명령어, 숫자
        string s,num;
        //배열크가
        int t;
        int is_reverse=0;
        int is_wrong=0;
        deque<int> dq;
        cin >> s >> t >> num;
        // [1,2,3,4] 여기서 숫자망 추출함
        string tmp ="";
        for(int i=0; i<num.length(); i++) {
            if(isdigit(num[i])) tmp+=num[i];
            else {
                if(!tmp.empty()) {
                    dq.push_back(stoi(tmp));
                    tmp="";
                }
            }
        }

        for(auto c:s) {
            if (c=='R') is_reverse = !is_reverse;
            else {
                if(dq.empty()) {
                    is_wrong=1;
                    break;
                }
                if (is_reverse) dq.pop_back(); 
                else dq.pop_front();
            }
        }
        if(is_wrong) cout << "error\n";
        else {
            if(is_reverse) {
                reverse(dq.begin(),dq.end());
            } 
            print_res(dq);
        }

        
    }

}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: