#include <bits/stdc++.h> using namespace std; int main(){ int m,n; cin>>m >>n; int V[n][m]; for(int i = 0; i < m;i++){ string W; cin>>W; for(int j = 0; j < W.size();j++){ if(W[j] == 'C'){ V[i][j] = 2; } if(W[j] == 'B'){ V[i][j] = 1; } if(W[j] == '.'){ V[i][j] = 0; } } } /* */ int a; cin>>a; string W; cin>>W; for(int i = 0; i < W.size();i++){ if(W[i] == 'D'){ for(int i = n - 1;i >= 0;i--){ for(int j = 0; j < m;j++){ if(V[i][j] == 1 || V[i][j] == 2){ int z = i; while(z + 1 < n && V[z + 1][j] == 0){ V[z + 1][j] = V[z][j]; V[z][j] = 0; z++; } } } } } if(W[i] == 'L'){ for(int i = 0 ;i < n;i++){ for(int j = m - 1; j >= 0;j--){ if(V[i][j] == 1 || V[i][j] == 2){ int z = j; while(z + 1 < m && V[i][z + 1] == 0){ V[i][z + 1] = V[i][z]; V[i][z] = 0; z++; } } } } } if(W[i] == 'P'){ for(int i = 0 ;i < n;i++){ for(int j = 0; j < m;j++){ if(V[i][j] == 1 || V[i][j] == 2){ int z = j; while(z + 1 < m && V[i][z + 1] == 0){ V[i][z + 1] = V[i][z]; V[i][z] = 0; z++; } } } } } if(W[i] == 'G'){ for(int i = 0;i < n;i++){ for(int j = 0; j < m;j++){ if(V[i][j] == 1 || V[i][j] == 2){ int z = i; while(z - 1 >= 0 && V[z - 1][j] == 0){ V[z - 1][j] = V[z][j]; V[z][j] = 0; z--; } } } } } } for(int i = 0;i < m;i++){ for(int j = 0; j < n;j++){ if(V[i][j] == 0){ cout<<"."; } if(V[i][j] == 1){ cout<<"B"; } if(V[i][j] == 2){ cout<<"C"; } } cout<<"\n"; } }
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | #include <bits/stdc++.h> using namespace std; int main(){ int m,n; cin>>m >>n; int V[n][m]; for(int i = 0; i < m;i++){ string W; cin>>W; for(int j = 0; j < W.size();j++){ if(W[j] == 'C'){ V[i][j] = 2; } if(W[j] == 'B'){ V[i][j] = 1; } if(W[j] == '.'){ V[i][j] = 0; } } } /* */ int a; cin>>a; string W; cin>>W; for(int i = 0; i < W.size();i++){ if(W[i] == 'D'){ for(int i = n - 1;i >= 0;i--){ for(int j = 0; j < m;j++){ if(V[i][j] == 1 || V[i][j] == 2){ int z = i; while(z + 1 < n && V[z + 1][j] == 0){ V[z + 1][j] = V[z][j]; V[z][j] = 0; z++; } } } } } if(W[i] == 'L'){ for(int i = 0 ;i < n;i++){ for(int j = m - 1; j >= 0;j--){ if(V[i][j] == 1 || V[i][j] == 2){ int z = j; while(z + 1 < m && V[i][z + 1] == 0){ V[i][z + 1] = V[i][z]; V[i][z] = 0; z++; } } } } } if(W[i] == 'P'){ for(int i = 0 ;i < n;i++){ for(int j = 0; j < m;j++){ if(V[i][j] == 1 || V[i][j] == 2){ int z = j; while(z + 1 < m && V[i][z + 1] == 0){ V[i][z + 1] = V[i][z]; V[i][z] = 0; z++; } } } } } if(W[i] == 'G'){ for(int i = 0;i < n;i++){ for(int j = 0; j < m;j++){ if(V[i][j] == 1 || V[i][j] == 2){ int z = i; while(z - 1 >= 0 && V[z - 1][j] == 0){ V[z - 1][j] = V[z][j]; V[z][j] = 0; z--; } } } } } } for(int i = 0;i < m;i++){ for(int j = 0; j < n;j++){ if(V[i][j] == 0){ cout<<"."; } if(V[i][j] == 1){ cout<<"B"; } if(V[i][j] == 2){ cout<<"C"; } } cout<<"\n"; } } |