https://www.acmicpc.net/problem/28279

#include <iostream>
#include <deque>
using namespace std;
deque<int> dq;
int x;
void d(int c)
{
if (c == 1)
{
cin >> x;
dq.push_front(x);
}
else if (c == 2)
{
cin >> x;
dq.push_back(x);
}
else if (c == 3)
{
if (dq.empty())
{
cout << "-1" << "\n";
}
else
{
cout << dq.front() << "\n";
dq.pop_front();
}
}
else if (c == 4)
{
if (dq.empty())
{
cout << "-1" << "\n";
}
else
{
cout << dq.back() << "\n";
dq.pop_back();
}
}
else if (c == 5)
{
cout << dq.size() << "\n";
}
else if (c == 6)
{
cout << dq.empty() << "\n";
}
else if (c == 7)
{
if (dq.empty())
{
cout << "-1" << "\n";
}
else
{
cout << dq.front() << "\n";
}
}
else if (c == 8)
{
if (dq.empty())
{
cout << "-1" << "\n";
}
else
{
cout << dq.back() << "\n";
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
int comment;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> comment;
d(comment);
}
}'알고리즘 > KOALA 알고리즘 스터디' 카테고리의 다른 글
| [BOJ/C++] 10815 숫자 카드 (1) | 2025.05.23 |
|---|---|
| [BOJ/C++] 1427 소트인사이드 (0) | 2025.05.15 |
| [BOJ/C++] 17298번 오큰수 (0) | 2025.05.02 |
| [BOJ/C++] 12847번 꿀 아르바이트 (0) | 2025.04.13 |
| [BOJ/C++] 2230번 수 고르기 (0) | 2025.04.03 |