Advertisement
UNoobAle

UVA 11831

Jan 19th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std; typedef long long ll; typedef unsigned long long ull; const int mod = 1e9 + 7, N = 1e5 + 1, inf = INT_MAX;
  3. #define fi first
  4. #define se second
  5. #define pb push_back
  6. #define mp make_pair
  7. #define ep emplace_back
  8. //#define int ll
  9.  
  10. char a[111][111], go[111111];
  11. int o, u, v, n, m, s, x, y, ans;
  12.  
  13. signed main()
  14. {
  15.     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  16.     while (cin >> n >> m >> s && n + m + s)
  17.     {
  18.         for (int i = 1; i <= n; i++)
  19.         {
  20.             for (int j = 1; j <= m; j++)
  21.             {
  22.                 cin >> a[i][j];
  23.                 if (a[i][j] == 'N' || a[i][j] == 'L' || a[i][j] == 'S' || a[i][j] == 'O')
  24.                 {
  25.                     if (a[i][j] == 'N') o = 0;
  26.                     if (a[i][j] == 'L') o = 1;
  27.                     if (a[i][j] == 'S') o = 2;
  28.                     if (a[i][j] == 'O') o = 3;
  29.                     u = i, v = j;
  30.                 }
  31.             }
  32.         }
  33.         ans = 0;
  34.         for (int i = 1; i <= s; i++)
  35.         {
  36.             cin >> go[i];
  37.         }
  38.         for (int i = 1; i <= s; i++)
  39.         {
  40.             if (go[i] == 'D')
  41.             {
  42.                 o = (o + 1) % 4;
  43.             }
  44.             if (go[i] == 'E')
  45.             {
  46.                 o = (o + 3) % 4;
  47.             }
  48.             if (go[i] == 'F')
  49.             {
  50.                 x = u, y = v;
  51.                 if (o == 0) --x;
  52.                 if (o == 1) ++y;
  53.                 if (o == 2) ++x;
  54.                 if (o == 3) --y;
  55.                 if (!x || !y || x > n || y > m || a[x][y] == '#') continue; //back to start which is u, v
  56.                 a[u][v] = '.';
  57.                 if (a[x][y] == '*') ans++;
  58.                 u = x, v = y;
  59.             }
  60.         }
  61.         cout << ans << endl;
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement