Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- string closestEnemy = ""; // No closest enemy the first loop
- int closestEnemyDistance = int.MaxValue; // Set the closest distance to the maximum possible value
- for (int i = 0; i < count; i++)
- {
- inputs = Console.ReadLine().Split(' ');
- String enemy = inputs[0]; // The name of this enemy
- int dist = int.Parse(inputs[1]); // The distance to your cannon of this enemy
- if (dist < closestEnemyDistance) // We have found a closer enemy!
- {
- closestEnemyDistance = dist; // Update the distance
- closestEnemy = enemy; // Update the name
- }
- }
- // Write an action using Console.WriteLine()
- // To debug: Console.Error.WriteLine("Debug messages...");
- // The turn has ended - Time to shoot the enemy!
- Console.WriteLine(closestEnemy);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement