Advertisement
Kimossab

CodinGame - Power of Thor

Nov 29th, 2015
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.94 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. typedef enum
  6. {
  7.     false,
  8.     true
  9. }bool;
  10.  
  11. /**
  12.  * Auto-generated code below aims at helping you parse
  13.  * the standard input according to the problem statement.
  14.  * ---
  15.  * Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders.
  16.  **/
  17. int main()
  18. {
  19.     int lightX; // the X position of the light of power
  20.     int lightY; // the Y position of the light of power
  21.     int initialTX; // Thor's starting X position
  22.     int initialTY; // Thor's starting Y position
  23.     scanf("%d%d%d%d", &lightX, &lightY, &initialTX, &initialTY);
  24.    
  25.     bool right, left, up, down;
  26.  
  27.     // game loop
  28.     while (1) {
  29.         int remainingTurns;
  30.         scanf("%d", &remainingTurns);
  31.         right = lightX > initialTX;
  32.         left = lightX < initialTX;
  33.         up = lightY < initialTY;
  34.         down = lightY > initialTY;
  35.         if(right && up)
  36.         {
  37.             printf("NE\n");
  38.             initialTX++;
  39.             initialTY--;
  40.         }
  41.         else if(right && down)
  42.         {
  43.             printf("SE\n");
  44.             initialTX++;
  45.             initialTY++;
  46.         }
  47.         else if(right)
  48.         {
  49.             printf("E\n");
  50.             initialTX++;
  51.         }
  52.         else if(left && down)
  53.         {
  54.             printf("SW\n");
  55.             initialTX--;
  56.             initialTY++;
  57.         }
  58.         else if(left && up)
  59.         {
  60.             printf("NW\n");
  61.             initialTX--;
  62.             initialTY--;
  63.         }
  64.         else if(left)
  65.         {
  66.             printf("W\n");
  67.             initialTX--;
  68.         }
  69.         else if(up)
  70.         {
  71.             printf("N\n");
  72.             initialTY--;
  73.         }
  74.         else
  75.         {
  76.             printf("S\n");
  77.             initialTY++;
  78.         }
  79.         //        printf("SE\n"); // A single line providing the move to be made: N NE E SE S SW W or NW
  80.     }
  81.  
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement