-
[BOJ] [C++] ACAlgorithm 2022. 7. 11. 02:56
https://www.acmicpc.net/problem/5430
#include <iostream> #include <deque> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int T; cin >> T; while (T--) { string p; cin >> p; int n; cin >> n; string arr; cin >> arr; deque<string> dq; bool isReversed = false; bool isError = false; string num; for (int i = 1; i < arr.length(); i++) { if (num != "" && (arr[i] == ',' || arr[i] == ']')) { dq.push_back(num); num = ""; continue; } num += arr[i]; } for (int i = 0; i < p.length(); i++) { if (p[i] == 'R') isReversed = !isReversed; else { if (dq.empty()) { isError = true; break; } if (!isReversed) dq.pop_front(); else dq.pop_back(); } } if (isError) { cout << "error\n"; continue; } cout << '['; if (isReversed) { for (auto i = dq.rbegin(); i < dq.rend(); i++) { cout << *i; if (i != dq.rend() - 1) cout << ','; } } else { for (auto i = dq.begin(); i < dq.end(); i++) { cout << *i; if (i != dq.end() - 1) cout << ','; } } cout << "]\n"; } return 0; }
'Algorithm' 카테고리의 다른 글
[BOJ][C++] 2473 새 용액 (0) 2022.07.11 [BOJ][C++]9019 DSLR (0) 2022.07.11 [BOJ][C++]16235 나무 제테크 (0) 2022.07.03 [BOJ][C++] 10989 수 정렬하기 3 (0) 2022.07.03 [BOJ] [C++] 16486 운동장 한 바퀴 (0) 2022.06.26