-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathonboarding.java
More file actions
34 lines (29 loc) · 1.22 KB
/
onboarding.java
File metadata and controls
34 lines (29 loc) · 1.22 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
import java.util.*;
import java.io.*;
import java.math.*;
/**
* CodinGame planet is being attacked by slimy insectoid aliens.
* <---
* Your program must destroy the enemy ships by shooting the closest enemy on each turn.
*Rules
*
*On each start of turn (within the game loop), you obtain information on the two closest enemies:
*enemy1 and dist1: the name and the distance to enemy 1.
*enemy2 and dist2: the name and the distance to enemy 2.
*Before your turn is over (end of the loop), output the value of either enemy1 or enemy2 to shoot the closest enemy
**/
class Player {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
// game loop
while (true) {
String enemy1 = in.next(); // name of enemy 1
int dist1 = in.nextInt(); // distance to enemy 1
String enemy2 = in.next(); // name of enemy 2
int dist2 = in.nextInt(); // distance to enemy 2
// Write an action using System.out.println()
// To debug: System.err.println("Debug messages...");
System.out.println(dist1<dist2?enemy1:enemy2); // You have to output a correct ship name to shoot ("Buzz", enemy1, enemy2, ...)
}
}
}