백준 문제풀이

백준 5430번 - C++

diligent_gideok 2022. 4. 30. 06:24
#include <bits/stdc++.h>
using namespace std;


void first(int k,deque<int> &D,int &flag) {
	//cout << "frist 시작"<<'\n';
	char ch;
	while (k--) {
		cin >> ch;
		if (ch == '[' || ch == ',') {
			int n;
			cin >> n;
			D.push_back(n);
		}
	}
	cin >> ch; // ']' 를 받아서 제거시킴
	//cout << "frist 끝" << '\n';
}

void second(string s, deque<int> &D,int &flag ) {
	//cout << "second 시작" << '\n';
	for (auto c : s) {
		if (c == 'R') {
			reverse(D.begin(), D.end());
		}
		else { // 'D'
			if (D.empty()) {
				flag = 1;
			}
			else {
				D.pop_front();
			}
		}

	}
	//cout << "second 끝 " << '\n';
}

void third(deque<int> &D) {
	cout << '[';
	while (!D.empty()) {
		cout << D.front();
		D.pop_front();
		if (!D.empty()) {
			cout << ',';
		}
	}
	cout << ']' << '\n';
}


int main(void) {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;


	while (n--) {

		int flag = 0;
		deque<int> D;
		
		//cout << "s 입력 : ";
		
		string s;
		cin >> s;
		//cout << "입력된 s : "<< s<<'\n';


		int k;
		cin >> k;


		first(k, D, flag);
		second(s, D, flag);

		if (flag == 1) {
			cout << "error\n";
		}
		else third(D);

	}
}

'백준 문제풀이' 카테고리의 다른 글

백준 11003번 - C++  (0) 2022.04.30
백준 10866번 - C++  (0) 2022.04.30
백준 1021번 - C++  (0) 2022.04.30
백준 18258번 - C++  (0) 2022.04.30
백준 10845번 - C++  (0) 2022.04.30