-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOnboarding.cs
56 lines (48 loc) · 1.57 KB
/
Onboarding.cs
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
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
/**
* The code below will read all the game information for you.
* On each game turn, information will be available on the standard input, you will be sent:
* -> the total number of visible enemies
* -> for each enemy, its name and distance from you
* The system will wait for you to write an enemy name on the standard output.
* Once you have designated a target:
* -> the cannon will shoot
* -> the enemies will move
* -> new info will be available for you to read on the standard input.
**/
class Player
{
static void Main(String[] args)
{
string[] inputs;
// game loop
while (true)
{
int count = int.Parse(Console.ReadLine()); // The number of current enemy ships within range
Console.Error.WriteLine("Count:" + count);
Enemy[] enemys = new Enemy[count];
for (int i = 0; i < count; i++)
{
inputs = Console.ReadLine().Split(' ');
enemys[i] = new Enemy(inputs[0], int.Parse(inputs[1]));
}
Array.Sort(enemys, delegate(Enemy en1, Enemy en2) {
return en1.Dist.CompareTo(en2.Dist);
});
Console.WriteLine(enemys[0].Name);
}
}
}
public class Enemy{
public string Name;
public int Dist;
public Enemy(string name, int dist){
this.Name = name;
this.Dist = dist;
}
}