-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavascript.js
35 lines (35 loc) · 848 Bytes
/
Javascript.js
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
let map = [];
let lanceMissile = null;
let listAvions = [];
const n = parseInt(readline());
for (let i = 0; i < n; i++) {
map.push(readline().split(""));
for (let j = 0; j < map[i].length; j++) {
let cell = map[i][j];
if (cell == ">" || cell == "<") {
listAvions.push({ i: i, j: j, type: cell });
} else if (cell == "^") {
lanceMissile = { i: i, j: j };
}
}
}
let listShot = [];
for (let i = 0; i < listAvions.length; i++) {
let a = listAvions[i];
listShot.push(Math.abs(a.j - lanceMissile.j) - Math.abs(a.i - lanceMissile.i));
}
listShot.sort((a, b) => {
return a - b;
});
let i = 1;
let current = listShot.shift();
let last = listShot[listShot.length - 1];
while (i <= last) {
if (i == current) {
console.log("SHOOT");
current = listShot.shift();
} else {
console.log("WAIT");
}
i++;
}