Advertisement
Guest User

CodingGame - Round 1

a guest
Oct 6th, 2014
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.IO;
  4. using System.Text;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7.  
  8. /**
  9.  * The code below will read all the game information for you.
  10.  * On each game turn, information will be available on the standard input, you will be sent:
  11.  * -> the total number of visible enemies
  12.  * -> for each enemy, its name and distance from you
  13.  * The system will wait for you to write an enemy name on the standard output.
  14.  * Once you have designated a target:
  15.  * -> the cannon will shoot
  16.  * -> the enemies will move
  17.  * -> new info will be available for you to read on the standard input.
  18.  **/
  19. class Player
  20. {
  21.     static void Main(String[] args)
  22.     {
  23.         string[] inputs;
  24.  
  25.         // game loop
  26.         while (true)
  27.         {
  28.             int count = int.Parse(Console.ReadLine()); // The number of current enemy ships within range
  29.             string closestEnemy = ""; // No closest enemy the first loop
  30.             int closestEnemyDistance = int.MaxValue; // Set the closest distance to the maximum possible value
  31.            
  32.             for (int i = 0; i < count; i++)
  33.             {
  34.                 inputs = Console.ReadLine().Split(' ');
  35.                 String enemy = inputs[0]; // The name of this enemy
  36.                
  37.                 int dist = int.Parse(inputs[1]); // The distance to your cannon of this enemy
  38.                 if (dist < closestEnemyDistance) // We have found a closer enemy!
  39.                 {
  40.                     closestEnemyDistance = dist; // Update the distance
  41.                     closestEnemy = enemy; // Update the name
  42.                 }
  43.             }
  44.  
  45.             // Write an action using Console.WriteLine()
  46.             // To debug: Console.Error.WriteLine("Debug messages...");
  47.  
  48.  
  49.             // The turn has ended - Time to shoot the enemy!
  50.             Console.WriteLine(closestEnemy);
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement