#include <iostream>
#include <queue>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N; cin >> N;
deque<int>dq;
while (N--) {
string s; cin >> s;
if (s == "push_back") {
int num; cin >> num;
dq.push_back(num);
}
else if (s == "push_front") {
int num; cin >> num;
dq.push_front(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";
}
}
}
'Algorithm ๐ง๐ปโ๐ป > ๋ฐฑ์ค(BOJ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค,c++] 10871๋ฒ - X๋ณด๋ค ์์ ์ (0) | 2021.10.25 |
---|---|
[๋ฐฑ์ค,c++] 10870๋ฒ - ํผ๋ณด๋์น ์5 (0) | 2021.10.25 |
[๋ฐฑ์ค,c++] 10867๋ฒ - ์ค๋ณต ๋นผ๊ณ ์ ๋ ฌํ๊ธฐ (0) | 2021.10.25 |
[๋ฐฑ์ค,c++] 10845๋ฒ - ํ (0) | 2021.10.25 |
[๋ฐฑ์ค,c++] 10828๋ฒ - ์คํ (0) | 2021.10.25 |
[๋ฐฑ์ค,c++] 10825๋ฒ - ๊ตญ์์ (0) | 2021.10.25 |
๋๊ธ