Advertisement
Guest User

Untitled

a guest
May 24th, 2017
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int d, n, direction, distance, x, y;
  8.  
  9.     cin >> d;
  10.  
  11.     while (d--)
  12.     {
  13.         cin >> n;
  14.         x = 0;
  15.         y = 0;
  16.         while (n--)
  17.         {
  18.             cin >> direction >> distance;
  19.             switch (direction)
  20.             {
  21.             case 0:
  22.                 y += distance;
  23.                 break;
  24.             case 1:
  25.                 y -= distance;
  26.                 break;
  27.             case 2:
  28.                 x += distance;
  29.                 break;
  30.             case 3:
  31.                 x -= distance;
  32.             }
  33.         }
  34.         if (x == 0 && y == 0)
  35.         {
  36.             cout << "studnia" << endl;
  37.         }
  38.         else
  39.         {
  40.             if (y > 0)
  41.                 cout << 0 << " " << y << endl;
  42.             else if (y < 0)
  43.                 cout << 1 << " " << -y << endl;
  44.             if (x > 0)
  45.                 cout << 2 << " " << x << endl;
  46.             else if (x < 0)
  47.                 cout << 3 << " " << -x << endl;
  48.         }
  49.     }
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement