-
Notifications
You must be signed in to change notification settings - Fork 0
/
2931.java
78 lines (61 loc) · 1.8 KB
/
2931.java
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.io.*;
public class Main {
static int R, C;
static char map[][];
public static void main(String[] args) throws Exception {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String rc[] = input.readLine().split(" ");
R = Integer.parseInt(rc[0]);
C = Integer.parseInt(rc[1]);
map = new char[R][C];
for(int i=0; i<R; i++) {
map[i] = input.readLine().toCharArray();
}
boolean find = false;
int pos[] = new int[2];
char ans = '.';
for(int i=0; i<R; i++) {
for(int j=0; j<C; j++) {
if(map[i][j] == '.') {
char result = ansCheck(i, j);
if(result != 'X') {
ans = result;
pos[0] = i+1;
pos[1] = j+1;
find = true;
break;
}
}
}
if(find) break;
}
System.out.printf("%d %d %c\n", pos[0], pos[1], ans);
}
// 상하좌우로 이동 가능 여부를 체크
private static char ansCheck(int r, int c) {
boolean top = r-1 > -1 && (map[r-1][c] == '|'
|| map[r-1][c] == '+'
|| map[r-1][c] == '1'
|| map[r-1][c] == '4') ? true : false;
boolean bottom = r+1 < R && (map[r+1][c] == '|'
|| map[r+1][c] == '+'
|| map[r+1][c] == '2'
|| map[r+1][c] == '3') ? true : false;
boolean left = c-1 > -1 && (map[r][c-1] == '-'
|| map[r][c-1] == '+'
|| map[r][c-1] == '1'
|| map[r][c-1] == '2') ? true : false;
boolean right = c+1 < C && (map[r][c+1] == '-'
|| map[r][c+1] == '+'
|| map[r][c+1] == '3'
|| map[r][c+1] == '4') ? true : false;
if(top && bottom && left && right) return '+';
else if(top && bottom) return '|';
else if(left && right) return '-';
else if(right && bottom) return '1';
else if(top && right) return '2';
else if(top && left) return '3';
else if(left && bottom) return '4';
return 'X';
}
}