#include <bits/stdc++.h> using namespace std; int T[501][501]; char inputy[500001]; int n,m,k; void schodzenie_gora(){ for (int i = 1; i <= n;i++){ int indeks = 0; for (int j = 1; j <= m;j++){ if (T[i][j] != 0){ indeks++; int tmp = T[i][j]; T[i][j] = 0; T[i][indeks] = tmp; }}}} void schodzenie_dol(){ for (int i = 1; i <= n;i++){ int indeks = m+1; for (int j = m; j >= 1;j--){ if (T[i][j] != 0){ indeks--; int tmp = T[i][j]; T[i][j] = 0; T[i][indeks] = tmp; }}}} void schodzenie_lewo(){ for (int i = 1; i <= m;i++){ int indeks = 0; for (int j = 1; j <= n;j++){ if (T[j][i] != 0){ indeks++; int tmp = T[j][i]; T[j][i] = 0; T[indeks][i] = tmp; }}}} void schodzenie_prawo(){ for (int i = 1; i <= m;i++){ int indeks = n+1; for (int j = n; j >= 1;j--){ if (T[j][i] != 0){ indeks--; int tmp = T[j][i]; T[j][i] = 0; T[indeks][i] = tmp; }}}} void schodzenie(char t){ if (t == 'G')schodzenie_gora(); if (t == 'D')schodzenie_dol(); if (t == 'L')schodzenie_lewo(); if (t == 'P')schodzenie_prawo(); } int main(){ scanf("%d %d \n",&m,&n); for (int i = 1; i <= m;i++){ for (int j = 1; j <= n;j++){ char c_temp; scanf("%c",&c_temp); if (c_temp == 'B'){ T[j][i] = 1; } if (c_temp == 'C'){ T[j][i] = -1; } } scanf("\n"); } scanf("%d \n",&k); for (int t = 0; t < k;t++){ scanf("%c",&inputy[t]); schodzenie(inputy[t]); } for (int j = 1; j <= m;j++){ for (int i = 1; i <= n;i++){ if(T[i][j] == 0)printf("."); if(T[i][j] == 1)printf("B"); if(T[i][j] == -1)printf("C"); } printf("\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 | #include <bits/stdc++.h> using namespace std; int T[501][501]; char inputy[500001]; int n,m,k; void schodzenie_gora(){ for (int i = 1; i <= n;i++){ int indeks = 0; for (int j = 1; j <= m;j++){ if (T[i][j] != 0){ indeks++; int tmp = T[i][j]; T[i][j] = 0; T[i][indeks] = tmp; }}}} void schodzenie_dol(){ for (int i = 1; i <= n;i++){ int indeks = m+1; for (int j = m; j >= 1;j--){ if (T[i][j] != 0){ indeks--; int tmp = T[i][j]; T[i][j] = 0; T[i][indeks] = tmp; }}}} void schodzenie_lewo(){ for (int i = 1; i <= m;i++){ int indeks = 0; for (int j = 1; j <= n;j++){ if (T[j][i] != 0){ indeks++; int tmp = T[j][i]; T[j][i] = 0; T[indeks][i] = tmp; }}}} void schodzenie_prawo(){ for (int i = 1; i <= m;i++){ int indeks = n+1; for (int j = n; j >= 1;j--){ if (T[j][i] != 0){ indeks--; int tmp = T[j][i]; T[j][i] = 0; T[indeks][i] = tmp; }}}} void schodzenie(char t){ if (t == 'G')schodzenie_gora(); if (t == 'D')schodzenie_dol(); if (t == 'L')schodzenie_lewo(); if (t == 'P')schodzenie_prawo(); } int main(){ scanf("%d %d \n",&m,&n); for (int i = 1; i <= m;i++){ for (int j = 1; j <= n;j++){ char c_temp; scanf("%c",&c_temp); if (c_temp == 'B'){ T[j][i] = 1; } if (c_temp == 'C'){ T[j][i] = -1; } } scanf("\n"); } scanf("%d \n",&k); for (int t = 0; t < k;t++){ scanf("%c",&inputy[t]); schodzenie(inputy[t]); } for (int j = 1; j <= m;j++){ for (int i = 1; i <= n;i++){ if(T[i][j] == 0)printf("."); if(T[i][j] == 1)printf("B"); if(T[i][j] == -1)printf("C"); } printf("\n"); } } |