Advertisement
Guest User

Power of Thor

a guest
Jun 1st, 2016
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. /**
  7. * Auto-generated code below aims at helping you parse
  8. * the standard input according to the problem statement.
  9. * ---
  10. * Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders.
  11. **/
  12. int main()
  13. {
  14.     int lightX; // the X position of the light of power
  15.     int lightY; // the Y position of the light of power
  16.     int initialTX; // Thor's starting X position
  17.     int initialTY; // Thor's starting Y position
  18.     cin >> lightX >> lightY >> initialTX >> initialTY; cin.ignore();
  19.     int OffsetX = 0;
  20.     int OffsetY = 0;
  21.  
  22.  
  23.     // game loop
  24.     while (1)
  25.     {
  26.         int remainingTurns; // The remaining amount of turns Thor can move. Do not remove this line.
  27.         cin >> remainingTurns; cin.ignore();
  28.  
  29.         OffsetX = abs(lightX - initialTX);
  30.         OffsetY = abs(lightY - initialTY);
  31.  
  32.         //NE NO SE SO
  33.         if (OffsetX == OffsetY)
  34.         {
  35.             if (lightX > initialTX)
  36.             {
  37.                 if (lightY < initialTY)
  38.                 {
  39.                     cout << "NE" << endl;
  40.                 }
  41.                 else
  42.                 {
  43.                     cout << "SE" << endl;
  44.                 }
  45.  
  46.             }
  47.             else
  48.             {
  49.                 if (lightY < initialTY)
  50.                 {
  51.                     cout << "NW" << endl;
  52.                 }
  53.                 else
  54.                 {
  55.                     cout << "SW" << endl;
  56.                 }
  57.             }
  58.         }
  59.  
  60.  
  61.  
  62.         if (OffsetX < OffsetY)
  63.         {
  64.             if (OffsetX == 0)
  65.             {
  66.                 if (lightY < initialTY)
  67.                 {
  68.                     cout << "N" << endl;
  69.                 }
  70.                 else
  71.                 {
  72.                     cout << "S" << endl;
  73.                 }
  74.             }
  75.             else
  76.             {
  77.                 if (lightY < initialTY) //NE NO
  78.                 {
  79.                     if (lightX < initialTX)
  80.                     {
  81.                         cout << "NO" << endl;
  82.                     }
  83.                     else
  84.                     {
  85.                         cout << "NE" << endl;
  86.                     }
  87.                 }
  88.                 else                   //SE SO
  89.                 {
  90.                     if (lightX < initialTX)
  91.                     {
  92.                         cout << "SO" << endl;
  93.                     }
  94.                     else
  95.                     {
  96.                         cout << "SE" << endl;
  97.                     }
  98.                 }
  99.             }
  100.         }
  101.         else //OffsetY < OffsetX
  102.         {
  103.             if (OffsetY == 0)
  104.             {
  105.                 if (lightX < initialTX)
  106.                 {
  107.                     cout << "W" << endl;
  108.                 }
  109.                 else
  110.                 {
  111.                     cout << "E" << endl;
  112.                 }
  113.             }
  114.             else //OffsetY < OffsetX but not 0
  115.             {
  116.                 if (lightX < initialTX)
  117.                 {
  118.                     if (lightY < initialTY)
  119.                     {
  120.                         cout << "NO" << endl;
  121.                     }
  122.                     else
  123.                     {
  124.                         cout << "SO" << endl;
  125.                     }
  126.                 }
  127.                 else
  128.                 {
  129.                     if (lightY < initialTY)
  130.                     {
  131.                         cout << "NE" << endl;
  132.                     }
  133.                     else
  134.                     {
  135.                         cout << "SE" << endl;
  136.                     }
  137.                 }
  138.             }
  139.         }
  140.     }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement