#include <iostream>
#include <queue>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N; cin >> N;
queue<int>q;
while (N--) {
string s; cin >> s;
if (s == "push") {
int num; cin >> num;
q.push(num);
}
else if (s == "pop") {
if (q.empty()) cout << -1 << "\n";
else {
cout << q.front() << "\n";
q.pop();
}
}
else if (s == "size") cout << q.size() << "\n";
else if (s == "empty") {
if (q.empty()) cout << 1 << "\n";
else cout << 0 << "\n";
}
else if (s == "front") {
if (q.empty()) cout << -1 << "\n";
else cout << q.front() << "\n";
}
else if (s == "back") {
if (q.empty())cout << -1 << "\n";
else cout << q.back() << "\n";
}
}
}
'Algorithm ๐ง๐ปโ๐ป > ๋ฐฑ์ค(BOJ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค,c++] 10870๋ฒ - ํผ๋ณด๋์น ์5 (0) | 2021.10.25 |
---|---|
[๋ฐฑ์ค,c++] 10867๋ฒ - ์ค๋ณต ๋นผ๊ณ ์ ๋ ฌํ๊ธฐ (0) | 2021.10.25 |
[๋ฐฑ์ค,c++] 10866๋ฒ - ๋ฑ (0) | 2021.10.25 |
[๋ฐฑ์ค,c++] 10828๋ฒ - ์คํ (0) | 2021.10.25 |
[๋ฐฑ์ค,c++] 10825๋ฒ - ๊ตญ์์ (0) | 2021.10.25 |
[๋ฐฑ์ค,c++] 10824๋ฒ - ๋ค ์ (0) | 2021.10.25 |
๋๊ธ