Advertisement
STANAANDREY

AOCMMXX d12p2

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