BOJ : https://www.acmicpc.net/problem/10845
큐에 대한 기본 구현을 묻는 문제이다.
더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#include <iostream>
#include <string>
#include <queue>
using namespace std;
queue<int> q;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
string str;
int N, num; cin >> N;
while (N--) {
cin >> str;
if (str == "push") {
cin >> num;
q.push(num);
}
if (str == "pop") {
if (q.empty()) cout << "-1\n";
else cout << q.front() << '\n', q.pop();
}
if (str == "size") {
cout << q.size() << '\n';
}
if (str == "empty") {
cout << q.empty() << '\n';
}
if (str == "front") {
if (q.empty()) cout << "-1\n";
else cout << q.front() << '\n';
}
if (str == "back") {
if (q.empty()) cout << "-1\n";
else cout << q.back() << '\n';
}
}
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
'algorithm > BOJ' 카테고리의 다른 글
BOJ 10820번 문자열 분석 (0) | 2020.01.12 |
---|---|
BOJ 10809번 알파벳 찾기 (0) | 2020.01.12 |
BOJ 10799번 쇠막대기 (0) | 2020.01.11 |
BOJ 9012번 괄호 (0) | 2020.01.11 |
BOJ 10828번 스택 (0) | 2020.01.11 |