1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <cstring>
using namespace std;

#define MAXSIZE 500
#define MAXMVSCNT 500001

int main()
{
  int n, m, k;
  char state[MAXSIZE][MAXSIZE];
  char mvs[MAXMVSCNT];
  cin >> n >> m;
  for (int i = 0; i < n; i++)
  {
    char stateln[MAXSIZE + 1];
    cin >> stateln;
    for (int j = 0; j < m; j++)
      state[i][j] = stateln[j];
  }
  cin >> k;
  cin >> mvs;
  for (int t = 0; t < k; t++)
  {
    switch (mvs[t])
    {
      case 'G':
        for (int j = 0; j < m; j++)
        {
          int ib = 0;
          for (int i = 0; i < n; i++)
            if (state[i][j] != '.')
              state[ib++][j] = state[i][j];
          while (ib < n)
            state[ib++][j] = '.';
        }
        break;
      case 'D':
        for (int j = 0; j < m; j++)
        {
          int ib = n - 1;
          for (int i = n - 1; i >= 0; i--)
            if (state[i][j] != '.')
              state[ib--][j] = state[i][j];
          while (ib >= 0)
            state[ib--][j] = '.';
        }
        break;
      case 'L':
        for (int i = 0; i < n; i++)
        {
          int jb = 0;
          for (int j = 0; j < m; j++)
            if (state[i][j] != '.')
              state[i][jb++] = state[i][j];
          while (jb < m)
            state[i][jb++] = '.';
        }
        break;
      case 'P':
        for (int i = 0; i < n; i++)
        {
          int jb = m - 1;
          for (int j = m - 1; j >= 0; j--)
            if (state[i][j] != '.')
              state[i][jb--] = state[i][j];
          while (jb >= 0)
            state[i][jb--] = '.';
        }
        break;
      default:
        break;
    }
  }
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < m; j++)
      cout << state[i][j]; 
    cout << endl;  
  }
  // system("pause");
}