본문 바로가기
Computer Science

APS 기본 실습 Ladder1 / 배열

by OKOK 2018. 12. 13.

1. 사다리 게임 문제 풀이

2. 2차원 배열 인덱스 유의

3. 어떤 것을 어떻게 볼지

4. 그리고 예제에서 무시할 것은 무시하고,

5. 헷갈리게 하지 안힉

6. 오케이

7. 단순하게 아래에서 올라와서 체크하는 것 


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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#define ARRAY_SIZE 100
enum { EMPTY, LADDER, END };
 
int deltaX[] = { 0-11 }; // 하좌우
int deltaY[] = { -100 }; // 하좌우
int arr[ARRAY_SIZE][ARRAY_SIZE] = { 0, };
int v[ARRAY_SIZE][ARRAY_SIZE] = { 0, };
int endX = 99;
int endY = 99;
int startX = 0;
 
void FindStartX(int y, int x) {
    if (y == 0) {   // 시작점 y 행까지 도착
        startX = x;
        return;
    }
 
    // 현재 위치에서 이동할 수 있는 4방향에 대해
    int left = x - 1;
    int right = x + 1;
 
    if (left >= 0 && arr[y][left] == LADDER) {
        arr[y][x] = EMPTY;
        FindStartX(y, left);
    }
    else if (right < ARRAY_SIZE && arr[y][right] == LADDER) {
        arr[y][x] = EMPTY;
        FindStartX(y, right);
    }
    else {
        FindStartX(y - 1, x);
    }
}
 
int main(void)
{
    int test_case = 0;
    int T = 10;
    freopen("input.txt""r", stdin);
    setbuf(stdout, NULL);
 
    for (test_case = 1; test_case <= T; ++test_case)
    {
        int tc = 0;
        char data = 0;
        startX = 0;
        scanf("%d "&tc);
 
        for (int y = 0; y < ARRAY_SIZE; y++) {
            for (int x = 0; x < ARRAY_SIZE; x++) {
                scanf("%c "&data);
 
                if (data == '0') {
                    arr[y][x] = EMPTY;
                }
                else if (data == '1') {
                    arr[y][x] = LADDER;
                }
                else if (data == '2') {
                    arr[y][x] = END;
                    endX = x;
                    endY = y;
                }
            }
        }
        FindStartX(endY, endX);
 
        // 표준출력(화면)으로 답안을 출력합니다.
        printf("#%d %d\n", tc, startX);
 
    }
    return 0//정상종료시 반드시 0을 리턴해야 합니다.
}
 
cs


댓글