#pragma region 라이브러리
#include <iostream>
#include <cmath>
#include <string>
#include <functional>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
#pragma endregion
#pragma region 최적화용
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0);
#define y first
#define x second
using IntPair = pair<int, int>;
#pragma endregion
int main()
{
deque<int> dq;
map<string, function<void(int)>> funcs
{
{"push_front", [&](int x) { dq.push_front(x); } },
{"push_back", [&](int x) { dq.push_back(x); } },
{"pop_front", [&](int x) { if (dq.empty()) cout << "-1\n"; else {
int val = dq.front();
dq.pop_front();
cout << val << '\n';
}}},
{"pop_back", [&](int x) { if (dq.empty()) cout << "-1\n"; else
{
int val = dq.back();
dq.pop_back();
cout << val << '\n';
}}},
{"size", [&](int x) { cout << dq.size() << '\n'; }},
{"empty", [&](int x) { cout << dq.empty() << '\n'; }},
{"front", [&](int x) { if (dq.empty()) cout << "-1\n"; else cout << dq.front() << '\n'; }},
{"back", [&](int x) { if (dq.empty()) cout << "-1\n"; else cout << dq.back() << '\n'; } },
};
int t;
cin >> t;
while (t--)
{
string str;
int n = 0;
cin >> str;
// 파라미터 넘겨야함
if (str.starts_with("push"))
cin >> n;
funcs[str](n);
}
}
'코딩테스트 > 백준' 카테고리의 다른 글
[브1] 10798 - 세로읽기 (0) | 2024.11.04 |
---|---|
[브1] 14467 - 소가 길을 건너간 이유 1 (0) | 2024.11.04 |
[브4] 13136 - Do Not Touch Anything (0) | 2024.07.17 |
[브5] 20492 - 세금 (0) | 2024.07.17 |
[실3] 1002 - 터렛 (1) | 2024.05.29 |