Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 오퍼레이팅시스템
- 정석
- 코딩
- DP
- Stack
- 백준
- Operating System
- 정석학술정보관
- 코테
- 컴공과
- 그래프
- cs
- OS
- Computer science
- 컴공
- coding
- vector
- 문제풀이
- 알고리즘
- 브루트포스
- 북리뷰
- 구현
- 자료구조
- 너비우선탐색
- 컴퓨터공학과
- 개발
- 오에스
- bfs
- c++
- 스택
Archives
- Today
- Total
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