Recent Posts
Notice
No Rules Rules
덱 (feat. 백준, 10866번) 본문
728x90
반응형
덱
https://www.acmicpc.net/problem/10866
반응형
// woohyeon.kim
// kim519620.tistory.com
#include <iostream>
#include <deque>
#include <cstring>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(NULL);
string str;
deque<int> ans;
register int N;
cin >> N;
for (register int n = 0, v; n < N; ++n) {
cin >> str;
if (!str.compare("push_front"))
cin >> v, ans.push_front(v);
else if (!str.compare("push_back"))
cin >> v, ans.push_back(v);
else if (!str.compare("pop_front"))
if (ans.empty())
cout << -1 << "\n";
else
cout << ans.front() << "\n", ans.pop_front();
else if (!str.compare("pop_back"))
if (ans.empty())
cout << -1 << "\n";
else
cout << ans.back() << "\n", ans.pop_back();
else if (!str.compare("size"))
cout << ans.size() << "\n";
else if (!str.compare("empty"))
if (ans.empty())
cout << 1 << "\n";
else
cout << 0 << "\n";
else if (!str.compare("front"))
if (ans.empty())
cout << -1 << "\n";
else
cout << ans.front() << "\n";
else if (!str.compare("back"))
if (ans.empty())
cout << -1 << "\n";
else
cout << ans.back() << "\n";
}
return 0;
}
// *&)*@*
자료구조 deque를 사용하여 문제의 요구사항대로 출력합니다.
728x90
반응형
'생활 > 코테' 카테고리의 다른 글
AC (feat. 백준, 5430번) (0) | 2022.08.13 |
---|---|
회전하는 큐 (feat. 백준, 1021번) (0) | 2022.08.13 |
프린터 큐 (feat. 백준, 1966번) (0) | 2022.08.12 |
요세푸스 문제 0 (feat. 백준, 11866번) (0) | 2022.08.12 |
카드2 (feat. 백준, 2164번) (0) | 2022.08.12 |
Comments