KDHzoot's Github

Code for study, project, etc

자세히보기

알고리즘/PS

[백준 14670] 병약한 영정

kdhzoot 2018. 5. 26. 10:10

간단한 매핑문제

배열을 -1로 초기화 해놨지만 입력되는 증상이 배열의 크기를 초과해 고칠 수 없지만 0을 받아오는 경우가 생겼다.

고쳐야하는 증상 S가 범위가 없음을 유의하면 된다.



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 <stdio.h>
#include <string.h>
using namespace std;
int n, m;
int arr[105];
int brr[105];
 
int main(void) {
    int a;
    scanf("%d"&n);
 
    memset(arr, -1sizeof(arr));
 
    for (int i = 0; i < n; i++) {
        int a, b;
        scanf("%d %d"&a, &b);
        arr[a] = b;
    }
 
    int cnt = 0;
    scanf("%d"&m);
    for (int i = 0; i < m; i++) {
        int q;
        cnt = 0;
        scanf("%d"&q);
        for (int j = 0; j < q; j++) {
            scanf("%d"&brr[j]);
            if (brr[j]<0 || brr[j]>100){
                cnt++;
                continue;
            }
            
            if (arr[brr[j]] == -1) {
                cnt++;
            }
        }
        if (cnt != 0) {
            printf("YOU DIED\n");
        }
        else {
            for (int j = 0; j < q; j++) {
                printf("%d ", arr[brr[j]]);
            }
            printf("\n");
        }
    }
}
cs


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

[백준 10539] 수빈이와 수열  (0) 2018.05.27
[백준 14671] 영정이의 청소  (0) 2018.05.26
[백준 14675] 단절점과 단절선  (0) 2018.05.26
[백준 12840] 창용이의 시계  (0) 2018.05.23
[백준 12842] 튀김 소보루  (0) 2018.05.23