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 40 41 42 43 44 45 46 47 | #include <queue> #include <stdio.h> #include <iostream> #include <string> using namespace std; int main() { int N; cin >> N; string input; queue<int> q; for (int i = 0; i < N; i++) { cin >> input; if (input == "push") { //push int num; cin >> num; q.push(num); //printf("%d\n", num); No print, if push. } else if (input == "front") { //front if (q.empty() == 1) printf("-1\n"); else printf("%d\n", q.front()); } else if (input == "back") { //back if (q.empty() == 1) { printf("-1\n"); else printf("%d\n", q.back()); } else if (input == "size") //size printf("%d\n", q.size()); else if (input == "pop") { //pop if (q.empty() == 1) printf("-1\n"); else { printf("%d\n", q.front()); q.pop(); } } else if (input == "empty") //empty printf("%d\n", q.empty()); } return 0; } | cs |
'Algorithm Problems > BOJ' 카테고리의 다른 글
[1924번] In 2007 2007년 - For Loop [C++] ☆ (0) | 2016.12.28 |
---|---|
[2439번] Star Shooting 2 별찍기2 - For loop [C++] (0) | 2016.12.28 |
[2839번] ŠEĆER(sugar) 설탕 배달 - In/Output [C++] ☆ (0) | 2016.12.27 |
[11718번] Output as is 그대로 출력하기 - In/Output[C++] (0) | 2016.12.27 |
[4673번] Self Number 셀프 넘버 - Method[Java] (0) | 2016.12.22 |