Advertisement
STANAANDREY

AOCMMXX d12p1

Dec 14th, 2020
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. //dirs:N-0,E-1,S-2,W-3;
  4. const int dirX[]= {0,1,0,-1};
  5. const int dirY[]= {1,0,-1,0};
  6. int x, y, dir = 1;
  7.  
  8. void rotate(int r) {
  9.     dir += r + 4;
  10.     dir %= 4;
  11. }
  12.  
  13. int main() {
  14.     freopen("text.in", "r", stdin);
  15.     char s[10];
  16.     while (cin >> s) {
  17.         char c = s[0];
  18.         int a = atoi(s + 1);
  19.         switch (c) {
  20.             case 'L': {
  21.                 rotate(-a / 90);
  22.                 break;
  23.             }
  24.             case 'R': {
  25.                 rotate(a / 90);
  26.                 break;
  27.             }
  28.             case 'N': {
  29.                 y += a;
  30.                 break;
  31.             }
  32.             case 'E': {
  33.                 x += a;
  34.                 break;
  35.             }
  36.             case 'S': {
  37.                 y -= a;
  38.                 break;
  39.             }
  40.             case 'W': {
  41.                 x -= a;
  42.                 break;
  43.             }
  44.             case 'F': {
  45.                 if (dir & 1) {
  46.                     x += dirX[dir] * a;
  47.                 } else {
  48.                     y += dirY[dir] * a;
  49.                 }
  50.                 break;
  51.             }
  52.         }
  53.         //cerr << x << ' ' << y << endl;
  54.     }
  55.     cout << abs(x) + abs(y) << endl;
  56.     return 0;
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement