짬뽕얼큰하게의 맨땅에 헤딩 :: 백준(BOJ) 10845

백준(BOJ) 10845

알고리즘 2018. 11. 26. 10:09

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 <iostream>
#include <cstdio>
#include <queue>
#include <string.h>
using namespace std;
 
queue<int> q;
 
int main(void){
  int N;
  scanf("%d"&N);
  scanf("%*c");
  while(N--){
    char str[20];
    scanf("%s", str);
    if(strcmp(str, "push"== 0){
      int n;
      scanf("%d"&n);
      q.push(n);
      scanf("%*c");
    }
    else if(strcmp(str, "pop"== 0){
        if(q.empty()) printf("-1\n");
        else{
          printf("%d\n", q.front());
          q.pop();
        }
    }
    else if(strcmp(str, "size"== 0){
        printf("%d\n", q.size());
    }
    else if(strcmp(str, "empty"== 0){
        if(q.empty()) printf("1\n");
        else printf("0\n");
    }
    else if(strcmp(str, "front"== 0){
        if(q.empty()) printf("-1\n");
        else printf("%d\n", q.front());
    }
    else if(strcmp(str, "back"== 0){
      if(q.empty()) printf("-1\n");
      else printf("%d\n", q.back());
    }
  }
 
}
 
cs


'알고리즘' 카테고리의 다른 글

백준(BOJ) 2309 일곱 난쟁이  (0) 2018.11.26
백준(BOJ) 2609 최대공약수와 최소공배수  (0) 2018.11.26
백준(BOJ) 2908  (0) 2018.11.26
백준(BOJ) 1157  (0) 2018.11.25
백준(BOJ) 1932  (0) 2018.11.25
블로그 이미지

짬뽕얼큰하게

,