forked from charlesfranciscodev/codingame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
there-is-no-spoon1.kt
57 lines (49 loc) · 1.33 KB
/
there-is-no-spoon1.kt
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
import java.util.Scanner
fun main(args : Array<String>) {
val empty = '.'
val node = '0'
val input = Scanner(System.`in`)
val width = input.nextInt() // the number of cells on the X axis
val height = input.nextInt() // the number of cells on the Y axis
if (input.hasNextLine()) {
input.nextLine()
}
val grid = ArrayList<String>(height)
for (y in 0 until height) {
val line = input.nextLine() // width characters, each either 0 or .
grid.add(line)
}
for (y in 0 until height) {
for (x in 0 until width) {
if (grid[y][x] == node) {
// node
val output = StringBuilder("$x $y ")
// right neighbor
var neighbor = empty
for (neighborX in x + 1 until width) {
neighbor = grid[y][neighborX]
if (neighbor == node) {
output.append("$neighborX $y ")
break
}
}
if (neighbor == empty) {
output.append("-1 -1 ")
}
// bottom neighbor
neighbor = empty
for (neighborY in y + 1 until height) {
neighbor = grid[neighborY][x]
if (neighbor == node) {
output.append("$x $neighborY")
break
}
}
if (neighbor == empty) {
output.append("-1 -1")
}
println(output)
}
}
}
}