-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathURI1855MaestersMap.java
More file actions
83 lines (77 loc) · 2.23 KB
/
URI1855MaestersMap.java
File metadata and controls
83 lines (77 loc) · 2.23 KB
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
79
80
81
82
83
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
/**
* See
* <a href="https://www.urionlinejudge.com.br/judge/en/problems/view/1855">Master's
* Map</a>
*
* @author Brian Yeicol Restrepo Tangarife
*/
public class URI1855MaestersMap {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
int x = Integer.parseInt(in.readLine());
int y = Integer.parseInt(in.readLine());
int i = 0;
int j = 0;
char[][] map = new char[x][y];
char direction = map[0][0];
for (int z = 0; z < y; z++) {
map[z] = in.readLine().toCharArray();
}
boolean solution = true;
boolean search = true;
while (search) {
if (i >= 0 && i < y && j >= 0 && j < x) {
switch (map[i][j]) {
case '*':
search = false;
break;
case '>':
case '^':
case '<':
case 'v':
direction = map[i][j];
map[i][j] = '!';
break;
case '!':
search = false;
solution = false;
break;
}
i = getPosI(i, direction);
j = getPosJ(j, direction);
} else {
search = false;
solution = false;
}
}
out.println(solution ? '*' : '!');
out.close();
}
private static int getPosI(int i, char direction) {
switch (direction) {
case '^':
i--;
break;
case 'v':
i++;
break;
}
return i;
}
private static int getPosJ(int j, char direction) {
switch (direction) {
case '<':
j--;
break;
case '>':
j++;
break;
}
return j;
}
}