Advertisement
Guest User

codingame-tutorial

a guest
Dec 8th, 2014
6,393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Foundation/Foundation.h>
  2.  
  3. /**
  4.  * The code below will read all the game information for you.
  5.  * On each game turn, information will be available on the standard input, you will be sent:
  6.  * -> the total number of visible enemies
  7.  * -> for each enemy, its name and distance from you
  8.  * The system will wait for you to write an enemy name on the standard output.
  9.  * Once you have designated a target:
  10.  * -> the cannon will shoot
  11.  * -> the enemies will move
  12.  * -> new info will be available for you to read on the standard input.
  13.  **/
  14. int main(int argc, const char * argv[]) {
  15.  
  16.     // game loop
  17.     while (1) {
  18.         int count; // The number of current enemy ships within range
  19.         scanf("%d", &count); fgetc(stdin);
  20.        
  21.         NSMutableString *enemyToTerminated = [[NSMutableString alloc] init];
  22.         int minDist = 0;
  23.        
  24.         for (int i = 0; i < count; i++) {
  25.             char enemy[50]; // The name of this enemy
  26.             int dist; // The distance to your cannon of this enemy
  27.             scanf("%s%d", enemy, &dist); fgetc(stdin);
  28.             NSString *enemyName = [NSString stringWithFormat:@"%s", enemy];
  29.             if (minDist > dist) {
  30.                 minDist = dist;
  31.                 [enemyToTerminated setString:enemyName];
  32.             }
  33.         }
  34.  
  35.         // Write an action using printf(). DON'T FORGET THE TRAILING NEWLINE \n
  36.         // To debug: fprintf(stderr, [@"Debug messages\n" UTF8String]);
  37.        
  38.         printf([enemyToTerminated UTF8String]);// printf("\n");
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement