728x90
반응형
[swexpert] 1210. Ladder1
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 76 77 78 | import java.util.Scanner; public class Solution { static int[][] data = new int[100][102]; public static void main(String[] args) { Scanner sc = new Scanner(System.in); for (int t = 1; t <= 10; t++) { int ts = sc.nextInt(); for (int x = 0; x < data.length; x++) { for (int y = 1; y < data[x].length - 1; y++) { data[x][y] = sc.nextInt(); } } for (int x = 0; x < data.length; x++) { for (int y = 0; y < data[x].length; y++) { if(data[x][y] == 2) { int start = 0; int flag = 0; int i = x, j = y; while(true) { switch (flag) { case 0: // 상 if(data[i-1][j] == 1) { i--; if(data[i][j-1] == 1) { j--; flag = 1; break; } else if(data[i][j+1] == 1) { j++; flag = 2; break; } } break; case 1: // 좌 if(data[i][j-1] == 1) { j--; } else { flag = 0; } break; case 2: // 우 if(data[i][j+1] == 1) { j++; } else { flag = 0; } break; } if ( i == 0 ) break; // 도착 } System.out.println(); System.out.print("#" + t + " " + (j-1)); } } } } } } | cs |
728x90
반응형
'Algorithm > SWEA' 카테고리의 다른 글
[swexpert] 1224. 최단 경로 (2) | 2019.02.12 |
---|---|
[swexpert] 1228. 암호문1 (0) | 2019.01.29 |
[swexpert] 1225. 암호생성기 (0) | 2019.01.11 |
[swexpert] 1206. View (0) | 2019.01.11 |
[swexpert] 5431. 민석이의과제체크하기 (0) | 2019.01.08 |