Notice
Recent Posts
Recent Comments
Link
Little Jay
[C++] 백준 5430번 틀 본문
#include <iostream>
#include <string>
#include <deque>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
bool check, err;
string s, numline;
int n;
while (t--) {
deque<int> dq;
check = true;
err = false;
cin >> s >> n >> numline;
int i = 1;
while (numline[i] != '\0') {
int x = 0;
while (numline[i] >= '0' && numline[i] <= '9') {
x *= 10;
x += int(numline[i] - '0');
i++;
}
if (x != 0) {
dq.push_back(x);
}
i++;
}
i = 0;
while (s[i] != '\0') {
if (s[i] == 'R') {
check = !check;
}
else if (s[i] == 'D') {
if (dq.empty()) {
cout << "error" << "\n";
err = true;
break;
}
if (check) {
dq.pop_front();
}
else {
dq.pop_back();
}
}
i++;
}
if (!err) {
cout << "[";
}
while (!dq.empty()) {
if (check) {
auto c = dq.front();
dq.pop_front();
cout << c;
}
else {
auto c = dq.back();
dq.pop_back();
cout << c;
}
if (!dq.empty())
cout << ", ";
}
if (!err) {
cout << "]" << "\n";
}
}
return 0;
}'알고리즘 > BOJ' 카테고리의 다른 글
| [C++] 백준 1912번 - 연속합 (0) | 2021.08.21 |
|---|---|
| [C++] 백준 1850번 - 최대공약수 (0) | 2021.08.21 |
| [C++] 백준 9093번 - 단어 뒤집기 (0) | 2021.08.19 |
| [C++] 백준 2606번 - 바이러스 (0) | 2021.08.19 |
| [C++] 백준 11724번 - 연결 요소의 개수 (0) | 2021.08.19 |
Comments