Advertisement
xTheEc0

CodinGame.com // Power of Thor // Easy

Oct 22nd, 2015
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. /**
  9.  * Auto-generated code below aims at helping you parse
  10.  * the standard input according to the problem statement.
  11.  * ---
  12.  * Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders.
  13.  **/
  14. int main()
  15. {
  16.     int lightX; // the X position of the light of power
  17.     int lightY; // the Y position of the light of power
  18.     int initialTX; // Thor's starting X position
  19.     int initialTY; // Thor's starting Y position
  20.    
  21.     cin >> lightX >> lightY >> initialTX >> initialTY; cin.ignore();
  22.  
  23.     int thorX = lightX - initialTX;
  24.     int thorY = lightY - initialTY;
  25.     char dir_name[4] = {'N', 'E', 'S', 'W'};
  26.     // game loop
  27.     while (1) {
  28.         int remainingTurns; // The remaining amount of turns Thor can move. Do not remove this line.
  29.         cin >> remainingTurns; cin.ignore();
  30.  
  31.         // Write an action using cout. DON'T FORGET THE "<< endl"
  32.         // To debug: cerr << "Debug messages..." << endl;
  33.         cerr << to_string(thorX) << " " << to_string(thorY) << endl;
  34.        
  35.         char dir[2] = {'\0', '\0'};
  36.         char *cd = &dir[0];
  37.         if (thorY != 0)
  38.         {
  39.             *cd = thorY > 0 ? dir_name[2] : dir_name[0];
  40.             thorY += thorY > 0? -1 : 1;
  41.             cd = &dir[1];
  42.         }
  43.         if (thorX != 0)
  44.         {
  45.             *cd = thorX > 0 ? dir_name [1] : dir_name [3];
  46.             thorX += thorX > 0 ? -1 : 1;
  47.         }
  48.        
  49.         if (dir[1] != '\0') cout << dir[0] << dir[1] << endl;
  50.         else cout << dir[0] << endl;
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement