Advertisement
Bassel_11

Untitled

Aug 29th, 2022
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4.  
  5. void DirectionalMove () {
  6.  
  7.     ll t, garbage, dir = 90;
  8.     string x;
  9.     cin >> t;
  10.  
  11.     while (t--) {
  12.         dir = 90;
  13.         cin >> garbage;
  14.         cin >> x;
  15.         for (ll i = 0; i < garbage; i++) {
  16.             if (x[i] == '0') {
  17.                 dir += 90;
  18.             } else if (x[i] == '1') {
  19.                 dir -= 90;
  20.             }
  21.         }
  22.         if (dir < 0 and dir >= -360) {
  23.             dir += 360;
  24.         }
  25.         if (dir < -360) {
  26.             dir *= -1;
  27.             dir -= 360;
  28.         }
  29.  
  30.         if (dir >= 360) {
  31.             dir %= 360;
  32.         }
  33.  
  34.         if (dir % 360 == 0 or dir == 0) {
  35.             cout << "N"<<endl;
  36.         } else if (dir % 270 == 0) {
  37.             cout << "W"<<endl;
  38.         } else if (dir % 180 == 0) {
  39.             cout << "S"<<endl;
  40.         } else if (dir % 90 == 0) {
  41.             cout << "E"<<endl;
  42.         }
  43.     }
  44. }
  45. int main() {
  46.     DirectionalMove();
  47.     return 0;
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement