본문 바로가기
Computer Science

Ladder1

by OKOK 2019. 1. 21.

1. 유연해질 필요

2. 단순하게 왼쪽 오른쪽이동

3. 하고 위로 한 칸씩 올리면 됨 


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
#include <stdio.h>
 
int board[100][100];
 
int main() {
    freopen("input.txt""r", stdin);
    int T, test_case;
    int start;
    int dx, dy;
    int i, j;
 
    for (T = 0; T < 10++T) {
        scanf("%d"&test_case);
        for (i = 0; i < 100++i) {
            for (j = 0; j < 100++j) {
                scanf("%d"&board[i][j]);
                if (board[i][j] == 2)
                    start = j;
            }
        }
        dx = start;
        dy = 99;
        while (dy > 0) {
            if ((dx > 0&& board[dy][dx - 1]) {
                while ((dx > 0&& board[dy][dx - 1])
                    --dx; // 왼쪽으로 갈 수 있는 방큼 감
            }
            else if ((dx < 99&& board[dy][dx + 1]) {
                while ((dx < 99&& board[dy][dx + 1])
                    ++dx; // 오른쪽으로 갈 수 있는 만큼 감
            }
            --dy; // 위로 이동 
        }
        printf("#%d %d\n", test_case, dx);
    }
    return 0;
}
cs

 


'Computer Science' 카테고리의 다른 글

String  (0) 2019.01.21
Ladder2  (0) 2019.01.21
IoT DataBase  (0) 2019.01.18
연락처 DataBase  (0) 2019.01.18
해적의 mini DB  (0) 2019.01.18

댓글