짬뽕얼큰하게의 맨땅에 헤딩 :: 짬뽕얼큰하게의 맨땅에 헤딩

백준(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
블로그 이미지

짬뽕얼큰하게

,

백준(BOJ) 2908

알고리즘 2018. 11. 26. 09:43
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <cstdio>
int main(void){
  int a, b;
  scanf("%d %d"&a, &b);
 
  int c = 0, d = 0;
  while(a){
    c*=10;
    c += a % 10;
    a /= 10;
  }
  while(b){
    d *=10;
    d += b %10;
    b /=10;
  }
  if( c > d) printf("%d", c);
  else printf("%d", d);
 
}
 
cs


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

백준(BOJ) 2609 최대공약수와 최소공배수  (0) 2018.11.26
백준(BOJ) 10845  (0) 2018.11.26
백준(BOJ) 1157  (0) 2018.11.25
백준(BOJ) 1932  (0) 2018.11.25
백준(BOJ) 11726  (0) 2018.11.25
블로그 이미지

짬뽕얼큰하게

,

백준(BOJ) 1157

알고리즘 2018. 11. 25. 23:15
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
#include <iostream>
#include <algorithm>
using namespace std;
int arr[100];
int main(void){
   char c;
   while((c = getchar()) != EOF && c != '\n'){
       if(c >= 'a') c -= 'a' - 'A';
       arr[c]++;
   }
   int result = 0;
   int res;
   bool unique = true;
   for(int i = 'A'; i <= 'Z' ; i++){
        if(result < arr[i]){
            result = arr[i];
            res = i;
            unique = true;
        }
        else if(result == arr[i]){
            unique = false;
        }
   }
   if(unique) printf("%c", res);
   else printf("?");
}
cs


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

백준(BOJ) 10845  (0) 2018.11.26
백준(BOJ) 2908  (0) 2018.11.26
백준(BOJ) 1932  (0) 2018.11.25
백준(BOJ) 11726  (0) 2018.11.25
백준(BOJ) 2920  (0) 2018.11.25
블로그 이미지

짬뽕얼큰하게

,