Advertisement
Sinux1

Power of Thor c++

Mar 3rd, 2016
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.66 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, thorx; // Thor's starting X position
  19.     int initialTY, thory; // Thor's starting Y position
  20.     cin >> lightX >> lightY >> initialTX >> initialTY; cin.ignore();
  21.     thorx = initialTX, thory = initialTY;
  22.  
  23.     // game loop
  24.     while (1) {
  25.         int remainingTurns; // The remaining amount of turns Thor can move. Do not remove this line.
  26.         cin >> remainingTurns; cin.ignore();
  27.        
  28.         // Write an action using cout. DON'T FORGET THE "<< endl"
  29.         // To debug: cerr << "Debug messages..." << endl;
  30.      
  31.     int distanceX = lightX - thorx;
  32.     int distanceY = lightY - thory;
  33.  
  34.        
  35.          if (abs(distanceX) == abs(distanceY))
  36.             {
  37.                 if (distanceX > 0 && distanceY > 0)
  38.                 {
  39.                     cout << "SE" << endl;
  40.                     thorx ++;
  41.                     thory ++;
  42.                     }
  43.                    
  44.                 else if (distanceX > 0 && distanceY < 0)
  45.                 {
  46.                     cout << "NE" << endl;
  47.                     thorx ++;
  48.                     thory -= 1;
  49.                     }
  50.                    
  51.                 else if (distanceX < 0 && distanceY > 0)
  52.                 {
  53.                     cout << "SW" << endl;
  54.                     thorx -= 1;
  55.                     thory ++ ;}
  56.                
  57.                 else
  58.                 {
  59.                     cout << "NW" << endl;
  60.                     thorx -= 1;
  61.                     thory -= 1;
  62.                 }
  63.             }
  64.                
  65.        
  66.          if (abs(distanceX) > abs(distanceY))
  67.          {
  68.              if (distanceX > 0)
  69.              {
  70.                 cout << "E" <<endl;
  71.                 thorx ++;}
  72.             else
  73.             {
  74.                 cout << "W" << endl;
  75.                 thorx -=1;}
  76.           }
  77.          if (abs(distanceX) < abs(distanceY))
  78.          {
  79.              if (distanceY > 0)
  80.              {
  81.                  cout << "S" << endl;
  82.                  thory ++;
  83.                  }
  84.             else
  85.             {
  86.                 cout << "N" << endl;
  87.                 thory -= 1;
  88.                 }
  89.           }
  90.        
  91.          
  92.              
  93.        
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement