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 |
Tags
- 컴공과
- OS
- 코테
- 스택
- 백준
- 정석
- 북리뷰
- 자료구조
- bfs
- 컴공
- Operating System
- 알고리즘
- Stack
- cs
- 오퍼레이팅시스템
- 구현
- coding
- 너비우선탐색
- Computer science
- 문제풀이
- c++
- vector
- 정석학술정보관
- 브루트포스
- 개발
- 컴퓨터공학과
- DP
- 오에스
- 코딩
- 그래프
Archives
- Today
- Total
Little Jay
[C++] 백준 10866번 덱 본문
#include <iostream>
#include <deque>
#include <string>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int testCase;
cin >> testCase;
deque<int> dq;
for (int i = 0; i < testCase; i++) {
string s;
cin >> s;
if (s == "push_front") {
int num;
cin >> num;
dq.push_front(num);
}
else if (s == "push_back") {
int num;
cin >> num;
dq.push_back(num);
}
else if (s == "pop_front") {
if (dq.empty()) {
cout << -1 << "\n";
}
else {
cout << dq.front() << "\n";
dq.pop_front();
}
}
else if (s == "pop_back") {
if (dq.empty()) {
cout << -1 << "\n";
}
else {
cout << dq.back() << "\n";
dq.pop_back();
}
}
else if (s == "size") {
cout << dq.size() << "\n";
}
else if (s == "empty") {
if (dq.empty()) {
cout << 1 << "\n";
}
else {
cout << 0 << "\n";
}
}
else if (s == "front") {
if (dq.empty()) {
cout << -1 << "\n";
}
else {
cout << dq.front() << "\n";
}
}
else if (s == "back") {
if (dq.empty()) {
cout << -1 << "\n";
}
else {
cout << dq.back() << "\n";
}
}
}
return 0;
}
'알고리즘 > BOJ' 카테고리의 다른 글
[C++] 백준 2869번 달팽이는 올라가고 싶다 (0) | 2021.04.04 |
---|---|
[C++] 백준 11651번 좌표 정렬하기2 (0) | 2021.04.02 |
[C++] 백준 10989번 수 정렬하기3 (0) | 2021.03.26 |
[C++] 백준 10845번 큐 (0) | 2021.03.26 |
[C++] 백준 2775번 부녀회장이 될테야 (0) | 2021.03.26 |
Comments