#include <cstdio> int main() { int n,m; scanf("%d %d", &n, &m); while ((getchar()) != '\n'); int tab[n][m]; int czyjestkol[m]; int czyjestwier[n]; char temp; int wiersz = 1; int kolumna = 1; for(int i = 1; i < n*m+n; i++){ scanf("%c", &temp); if (temp == '.' || temp == 'B' || temp == 'C'){ tab[kolumna][wiersz] = int(temp); czyjestkol[kolumna] = 1; czyjestwier[wiersz] = 1; if (kolumna == m){ kolumna = 1; wiersz++; } else{ kolumna++; } } } int k = 0; scanf("%d", &k); while ((getchar()) != '\n'); for (int i = 0; i < k; i++){ scanf("%c", &temp); if (temp == 'G'){ for (int j = 1; j <= m; j++){ if (czyjestkol[j] == 1){ int count = 1; for (int l = 1; l <= n; l++){ if (tab[j][l] == 66 || tab[j][l] == 67){ tab[j][count] = tab[j][l]; if (l != 1){ tab[j][l] = 46; } l = 1 + count; count++; } } } } } if (temp == 'D'){ for (int j = 1; j <= m; j++){ if (czyjestkol[j] == 1){ int count = 0; for (int l = n; l > 0; l--){ if (tab[j][l] == 66 || tab[j][l] == 67){ tab[j][n-count] = tab[j][l]; if (l != n){ tab[j][l] = 46; } l = n - count; count++; } } } } } if (temp == 'L'){ for (int j = 1; j <= n; j++){ if (czyjestwier[j] == 1){ int count = 1; for (int l = 1; l <= m; l++){ if (tab[l][j] == 66 || tab[l][j] == 67){ tab[count][j] = tab[l][j]; if (l != 1){ tab[l][j] = 46; } l = 1 + count; count++; } } } } } if (temp == 'P'){ for (int j = 1; j <= n; j++){ if (czyjestwier[j] == 1){ int count = 0; for (int l = m; l > 0; l--){ if (tab[l][j] == 66 || tab[l][j] == 67){ tab[m-count][j] = tab[l][j]; if (l != m){ tab[l][j] = 46; } l = m - count; count++; } } } } } } wiersz = 1; kolumna = 1; for (int i = 0; i < n*m; ++i) { temp = char(tab[kolumna][wiersz]); printf("%c", temp); if (kolumna == m){ printf("\n"); kolumna = 1; wiersz++; } else{ kolumna++; } } return 0; }
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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | #include <cstdio> int main() { int n,m; scanf("%d %d", &n, &m); while ((getchar()) != '\n'); int tab[n][m]; int czyjestkol[m]; int czyjestwier[n]; char temp; int wiersz = 1; int kolumna = 1; for(int i = 1; i < n*m+n; i++){ scanf("%c", &temp); if (temp == '.' || temp == 'B' || temp == 'C'){ tab[kolumna][wiersz] = int(temp); czyjestkol[kolumna] = 1; czyjestwier[wiersz] = 1; if (kolumna == m){ kolumna = 1; wiersz++; } else{ kolumna++; } } } int k = 0; scanf("%d", &k); while ((getchar()) != '\n'); for (int i = 0; i < k; i++){ scanf("%c", &temp); if (temp == 'G'){ for (int j = 1; j <= m; j++){ if (czyjestkol[j] == 1){ int count = 1; for (int l = 1; l <= n; l++){ if (tab[j][l] == 66 || tab[j][l] == 67){ tab[j][count] = tab[j][l]; if (l != 1){ tab[j][l] = 46; } l = 1 + count; count++; } } } } } if (temp == 'D'){ for (int j = 1; j <= m; j++){ if (czyjestkol[j] == 1){ int count = 0; for (int l = n; l > 0; l--){ if (tab[j][l] == 66 || tab[j][l] == 67){ tab[j][n-count] = tab[j][l]; if (l != n){ tab[j][l] = 46; } l = n - count; count++; } } } } } if (temp == 'L'){ for (int j = 1; j <= n; j++){ if (czyjestwier[j] == 1){ int count = 1; for (int l = 1; l <= m; l++){ if (tab[l][j] == 66 || tab[l][j] == 67){ tab[count][j] = tab[l][j]; if (l != 1){ tab[l][j] = 46; } l = 1 + count; count++; } } } } } if (temp == 'P'){ for (int j = 1; j <= n; j++){ if (czyjestwier[j] == 1){ int count = 0; for (int l = m; l > 0; l--){ if (tab[l][j] == 66 || tab[l][j] == 67){ tab[m-count][j] = tab[l][j]; if (l != m){ tab[l][j] = 46; } l = m - count; count++; } } } } } } wiersz = 1; kolumna = 1; for (int i = 0; i < n*m; ++i) { temp = char(tab[kolumna][wiersz]); printf("%c", temp); if (kolumna == m){ printf("\n"); kolumna = 1; wiersz++; } else{ kolumna++; } } return 0; } |