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
83
84
85
86
87
88
89
90
#include <cstdio>
#include <iostream>

using namespace std;

int main()
{
    int m,n,k;
    string moves;
    string in;
    scanf("%d %d",&n,&m);
    int tab[n][m];
    for(int y=0;y<n;y++)
    {
        cin >> in;
        for(int x = 0; x<m; x++)
        {
            if(in[x]=='.')
                tab[y][x]=0;
            else if(in[x]=='B')
                tab[y][x]=1;
            else if(in[x]=='C')
                tab[y][x]=2;
        }
    }
    scanf("%d",&k);
    cin>>moves;
    for(int i = 0; i<k;i++){
        if(moves[i] == 'G'){
            for(int x = 0; x < m; x++){
                for(int move = 0; move < n; move++) {
                    for(int y = 1; y < n; y++){
                        if(tab[y-1][x] == 0 && (tab[y][x] == 1 || tab[y][x] == 2)){
                            tab[y-1][x] = tab[y][x];
                            tab[y][x] = 0;
                        }
                    }
                }
            }
        }
        else if(moves[i] == 'D'){
            for(int x = 0; x<m; x++){
                for(int move = 0; move < n; move++) {
                    for(int y = n-2; y >= 0; y--){
                        if(tab[y+1][x] == 0 && (tab[y][x] == 1 || tab[y][x] == 2)){
                            printf("[%d,%d] -> [%d,%d] | %d -> %d\n",y,x,y+1,x,tab[y][x],tab[y+1][x]);
                            tab[y+1][x] = tab[y][x];
                            tab[y][x] = 0;
                        }
                    }
                }
            }
        }
        else if(moves[i] == 'L'){
            for(int y = 0; y < n; y++){
                for(int move = 0; move < m; move++) {
                    for(int x = 1; x < m; x++){
                        if(tab[y][x-1] == 0 && (tab[y][x] == 1 || tab[y][x] == 2)){
                            tab[y][x-1] = tab[y][x];
                            tab[y][x] = 0;
                        }
                    }
                }
            }
        }
        else if(moves[i] == 'P'){
            for(int y = 0; y < n; y++){
                for(int move = 0; move < m; move++) {
                    for(int x = m-2; x >= 0; x--){
                        if(tab[y][x+1] == 0 && (tab[y][x] == 1 || tab[y][x] == 2)){
                            tab[y][x+1] = tab[y][x];
                            tab[y][x] = 0;
                        }
                    }
                }
            }
        }
    }
    for(int y = 0; y < n; y++){
        for(int x = 0; x < m; x++){
            if(tab[y][x] == 0)
                printf(".");
            else if(tab[y][x] == 1)
                printf("B");
            else if(tab[y][x] == 2)
                printf("C");
        }
        printf("\n");
    }
}