Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
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
Archives
Today
Total
관리 메뉴

최's 먹공로그

SW expert Academy 1210_[S/W 문제해결 기본] 2일차_Ladder1 본문

APS

SW expert Academy 1210_[S/W 문제해결 기본] 2일차_Ladder1

ChoiSH313 2019. 2. 3. 16:19

https://www.swexpertacademy.com/main/code/problem/problemDetail.do

 

 

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
import java.util.Scanner;
 
public class Solution_1210_SW문제해결기본2일차_Ladder1_최성호 {
 
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        for(int tc = 1; tc <= 10; tc++) {
            
            int t = sc.nextInt();
            int[][] arr = new int[100][100];
            for (int i = 0; i < arr.length; i++) {
                for (int j = 0; j < arr.length; j++) {
                    arr[i][j] = sc.nextInt();
                }
            }
            int index = 0;
            int start = 0;
            
            for (int j = 0; j < arr.length; j++) { // 꽝이 걸리는 지점에서 거꾸로 올라오기
                if(arr[99][j] == 2)
                    start = j; // 꽝인 지점의 인덱스를 저장
            } // start = 57
            for(int i = 98; i > 0; i--) { // 올라가는 변수
                
                if(start-1 >= 0) {
                    if(arr[i][start-1== 1) { // 왼쪽으로 빠지는 경우
                        
                        while(true) {
                            if(start >= 0 && arr[i][start] == 1) {
                                start--;
                            }
                            else {
                                index = start+1// 왼쪽 옆 값이 1이 아닐때는 마지막으로 1이었던 지점의 인덱스를 저장
                                break;
                            }
                        }
                        start = index; // 마지막으로 1이었던 지점의 인덱스를 반환
                        continue;
                    }
                }
                
                if(start+1 <= 99) {
                    if(arr[i][start+1== 1) { // 오른쪽으로 빠지는 경우
                        while(true) {
                            if(start <= 99 && arr[i][start] == 1) {
                                start++;
                            }
                            else {
                                index = start-1;
                                break;
                            }
                        }
                        start = index;
                        continue;
                    }
                }
            } // for
            
            System.out.println();
            System.out.println("#" + tc + " " + start);
            
        } // end of tc
        
    } // end of main
 
}
 
cs