#include <cstdio> int main() { int n, m; scanf("%i", &n); scanf("%i", &m); char tab[n][m]; int l_k = 0; for (int i = 0; i < n; ++i) { scanf("%s", &tab[i]); } for (int i = 0; i < n; ++i) { // TUTAJ LICZE BEZ SENSU ILE JEST NIE KROPEK; MOGE TO ROBIĆ W FORZE NA GÓRZE ALE NWM JAK for (int j = 0; j < m; ++j) { if (tab[i][j] != '.') l_k++; } } int y[l_k]; int pre_y[l_k]; int x[l_k]; int pre_x[l_k]; char c[l_k]; int k_iterator = 0; for (int i = 0; i < n; ++i) { // TUTAJ LICZE BEZ SENSU ILE JEST NIE KROPEK; MOGE TO ROBIĆ W FORZE NA GÓRZE ALE NWM JAK for (int j = 0; j < m; ++j) { if (tab[i][j] != '.') { y[k_iterator] = i; x[k_iterator] = j; pre_y[k_iterator] = i; pre_x[k_iterator] = j; c[k_iterator] = tab[i][j]; k_iterator++; } } } int l_moves; scanf("%d", &l_moves); char* moves = new char[l_moves]; scanf("%s", moves); /* -------------- KONIEC INPUTU --------------*/ for (int nr_m = 0; nr_m < l_moves; ++nr_m) { if (((moves[nr_m] == 71 && moves[nr_m + 1] != 68) || (moves[nr_m] == 68 && moves[nr_m + 1] != 71) || (moves[nr_m] == 76 && moves[nr_m + 1] != 80) || (moves[nr_m] == 80 && moves[nr_m + 1] != 76) || (moves[nr_m] == 71 && moves[nr_m + 1] != 71) || (moves[nr_m] == 68 && moves[nr_m + 1] != 68) || (moves[nr_m] == 76 && moves[nr_m + 1] != 76) || (moves[nr_m] == 80 && moves[nr_m + 1] != 80) )) { switch (moves[nr_m]) { case 71: //G for (int i = 0; i < l_k; ++i) { if (pre_y[i] != 0) { int l_cor = 0; for (int j = 0; j < l_k; ++j) { if (pre_y[j] < pre_y[i] && pre_x[j] == pre_x[i]) { l_cor++; } } y[i] -= pre_y[i] - l_cor; } } break; case 68: // D for (int i = 0; i < l_k; ++i) { if (pre_y[i] != n - 1) { int l_cor = 0; for (int j = 0; j < l_k; ++j) { if (pre_y[j] > pre_y[i] && pre_x[j] == pre_x[i]) { l_cor++; } } y[i] += (n - pre_y[i]) - l_cor - 1; } } break; case 76: // L for (int i = 0; i < l_k; ++i) { if (pre_x[i] != 0) { int l_cor = 0; for (int j = 0; j < l_k; ++j) { if (pre_x[j] < pre_x[i] && pre_y[j] == pre_y[i]) { l_cor++; } } x[i] -= pre_x[i] - l_cor; } } break; case 80: // P for (int i = 0; i < l_k; ++i) { if (pre_x[i] != m - 1) { int l_cor = 0; for (int j = 0; j < l_k; ++j) { if (pre_x[j] > pre_x[i] && pre_y[j] == pre_y[i]) { l_cor++; } } x[i]+= (m - pre_x[i]) - l_cor - 1; } } break; default: break; } for (int i = 0; i < l_k; ++i) { pre_x[i] = x[i]; pre_y[i] = y[i]; } } } for (int i = 0; i < n; ++i) { // STRASZNIE ZŁOŻONE WYŚWITLANIE n * m * l_k WTF for (int j = 0; j < m; ++j) { char out = '.'; for (int k = 0; k < l_k; ++k) { if (y[k] == i && x[k] == j) { out = c[k]; break; } } printf("%c", out); } printf("\n"); } 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 123 124 125 126 127 128 129 130 131 132 133 134 | #include <cstdio> int main() { int n, m; scanf("%i", &n); scanf("%i", &m); char tab[n][m]; int l_k = 0; for (int i = 0; i < n; ++i) { scanf("%s", &tab[i]); } for (int i = 0; i < n; ++i) { // TUTAJ LICZE BEZ SENSU ILE JEST NIE KROPEK; MOGE TO ROBIĆ W FORZE NA GÓRZE ALE NWM JAK for (int j = 0; j < m; ++j) { if (tab[i][j] != '.') l_k++; } } int y[l_k]; int pre_y[l_k]; int x[l_k]; int pre_x[l_k]; char c[l_k]; int k_iterator = 0; for (int i = 0; i < n; ++i) { // TUTAJ LICZE BEZ SENSU ILE JEST NIE KROPEK; MOGE TO ROBIĆ W FORZE NA GÓRZE ALE NWM JAK for (int j = 0; j < m; ++j) { if (tab[i][j] != '.') { y[k_iterator] = i; x[k_iterator] = j; pre_y[k_iterator] = i; pre_x[k_iterator] = j; c[k_iterator] = tab[i][j]; k_iterator++; } } } int l_moves; scanf("%d", &l_moves); char* moves = new char[l_moves]; scanf("%s", moves); /* -------------- KONIEC INPUTU --------------*/ for (int nr_m = 0; nr_m < l_moves; ++nr_m) { if (((moves[nr_m] == 71 && moves[nr_m + 1] != 68) || (moves[nr_m] == 68 && moves[nr_m + 1] != 71) || (moves[nr_m] == 76 && moves[nr_m + 1] != 80) || (moves[nr_m] == 80 && moves[nr_m + 1] != 76) || (moves[nr_m] == 71 && moves[nr_m + 1] != 71) || (moves[nr_m] == 68 && moves[nr_m + 1] != 68) || (moves[nr_m] == 76 && moves[nr_m + 1] != 76) || (moves[nr_m] == 80 && moves[nr_m + 1] != 80) )) { switch (moves[nr_m]) { case 71: //G for (int i = 0; i < l_k; ++i) { if (pre_y[i] != 0) { int l_cor = 0; for (int j = 0; j < l_k; ++j) { if (pre_y[j] < pre_y[i] && pre_x[j] == pre_x[i]) { l_cor++; } } y[i] -= pre_y[i] - l_cor; } } break; case 68: // D for (int i = 0; i < l_k; ++i) { if (pre_y[i] != n - 1) { int l_cor = 0; for (int j = 0; j < l_k; ++j) { if (pre_y[j] > pre_y[i] && pre_x[j] == pre_x[i]) { l_cor++; } } y[i] += (n - pre_y[i]) - l_cor - 1; } } break; case 76: // L for (int i = 0; i < l_k; ++i) { if (pre_x[i] != 0) { int l_cor = 0; for (int j = 0; j < l_k; ++j) { if (pre_x[j] < pre_x[i] && pre_y[j] == pre_y[i]) { l_cor++; } } x[i] -= pre_x[i] - l_cor; } } break; case 80: // P for (int i = 0; i < l_k; ++i) { if (pre_x[i] != m - 1) { int l_cor = 0; for (int j = 0; j < l_k; ++j) { if (pre_x[j] > pre_x[i] && pre_y[j] == pre_y[i]) { l_cor++; } } x[i]+= (m - pre_x[i]) - l_cor - 1; } } break; default: break; } for (int i = 0; i < l_k; ++i) { pre_x[i] = x[i]; pre_y[i] = y[i]; } } } for (int i = 0; i < n; ++i) { // STRASZNIE ZŁOŻONE WYŚWITLANIE n * m * l_k WTF for (int j = 0; j < m; ++j) { char out = '.'; for (int k = 0; k < l_k; ++k) { if (y[k] == i && x[k] == j) { out = c[k]; break; } } printf("%c", out); } printf("\n"); } return 0; } |