Advertisement
abhisekp

CodinGame - Onboarding

Jan 31st, 2015
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1.         // game loop
  2.         while (true) {
  3.             int count = in.nextInt(); // The number of current enemy ships within range
  4.             String closestEnemy = "";
  5.             int minDist = 1000;
  6.             for (int i = 0; i < count; i++) {
  7.                 String enemy = in.next(); // The name of this enemy
  8.                 int dist = in.nextInt(); // The distance to your cannon of this enemy
  9.                 if(dist <= minDist) {
  10.                     minDist = dist;
  11.                     closestEnemy = enemy;
  12.                 }
  13.             }
  14.  
  15.             System.out.println(closestEnemy); // The name of the most threatening enemy (HotDroid is just one example)
  16.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement