#include <iostream> using namespace std; int main() { int sze = 0, wys = 0, ilru = 0; string ru; string pla0[1000]; char pla[1000][1000]; cin >> wys >> sze; for (int i = 0; i < wys; i++) { cin >> pla0[i]; } cin >> ilru; cin >> ru; for (int y = 0; y < wys; y++) { for (int x = 0; x < sze; x++) { pla[y][x] = pla0[y][x]; } } for (int i = 0; i < ru.length(); i++) { if (ru[i] == 'G') { bool por = false; for (int j = 0; j < sze; j++) { int ter = 0; for (int i = 0; i < wys; i++) { if (pla[i][j] == '.') continue; if (pla[ter][j] == '.') { pla[ter][j] = pla[i][j]; pla[i][j] = '.'; por = true; } else { ter++; if (ter != i) { pla[ter][j] = pla[i][j]; pla[i][j] = '.'; por = true; } } } } } else if (ru[i] == 'D') { bool por = false; for (int j = 0; j < sze; j++) { int ter = sze - 1; for (int i = wys - 1; i >= 0; i--) { if (pla[i][j] == '.') continue; if (pla[ter][j] == '.') { pla[ter][j] = pla[i][j]; pla[i][j] = '.'; por = true; } else { ter--; if (ter != i) { pla[ter][j] = pla[i][j]; pla[i][j] = '.'; por = true; } } } } } else if (ru[i] == 'L') { bool por = false; for (int i = 0; i < wys; i++) { int ter = 0; for (int j = 0; j < sze; j++) { if (pla[i][j] == '.') continue; if (pla[i][ter] == '.') { pla[i][ter] = pla[i][j]; pla[i][j] = '.'; por = true; } else { ter++; if (ter != j) { pla[i][ter] = pla[i][j]; pla[i][j] = '.'; por = true; } } } } } else if (ru[i] == 'P') { bool por = false; for (int i = 0; i < wys; i++) { int ter = sze - 1; for (int j = sze - 1; j >= 0; j--) { if (pla[i][j] == '.') continue; if (pla[i][ter] == '.') { pla[i][ter] = pla[i][j]; pla[i][j] = '.'; por = true; } else { ter--; if (ter != j) { pla[i][ter] = pla[i][j]; pla[i][j] = '.'; por = true; } } } }; } } for (int z = 0; z < wys; z++) { for (int x = 0; x < sze; x++) { cout << pla[z][x]; } cout << endl; } }
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 | #include <iostream> using namespace std; int main() { int sze = 0, wys = 0, ilru = 0; string ru; string pla0[1000]; char pla[1000][1000]; cin >> wys >> sze; for (int i = 0; i < wys; i++) { cin >> pla0[i]; } cin >> ilru; cin >> ru; for (int y = 0; y < wys; y++) { for (int x = 0; x < sze; x++) { pla[y][x] = pla0[y][x]; } } for (int i = 0; i < ru.length(); i++) { if (ru[i] == 'G') { bool por = false; for (int j = 0; j < sze; j++) { int ter = 0; for (int i = 0; i < wys; i++) { if (pla[i][j] == '.') continue; if (pla[ter][j] == '.') { pla[ter][j] = pla[i][j]; pla[i][j] = '.'; por = true; } else { ter++; if (ter != i) { pla[ter][j] = pla[i][j]; pla[i][j] = '.'; por = true; } } } } } else if (ru[i] == 'D') { bool por = false; for (int j = 0; j < sze; j++) { int ter = sze - 1; for (int i = wys - 1; i >= 0; i--) { if (pla[i][j] == '.') continue; if (pla[ter][j] == '.') { pla[ter][j] = pla[i][j]; pla[i][j] = '.'; por = true; } else { ter--; if (ter != i) { pla[ter][j] = pla[i][j]; pla[i][j] = '.'; por = true; } } } } } else if (ru[i] == 'L') { bool por = false; for (int i = 0; i < wys; i++) { int ter = 0; for (int j = 0; j < sze; j++) { if (pla[i][j] == '.') continue; if (pla[i][ter] == '.') { pla[i][ter] = pla[i][j]; pla[i][j] = '.'; por = true; } else { ter++; if (ter != j) { pla[i][ter] = pla[i][j]; pla[i][j] = '.'; por = true; } } } } } else if (ru[i] == 'P') { bool por = false; for (int i = 0; i < wys; i++) { int ter = sze - 1; for (int j = sze - 1; j >= 0; j--) { if (pla[i][j] == '.') continue; if (pla[i][ter] == '.') { pla[i][ter] = pla[i][j]; pla[i][j] = '.'; por = true; } else { ter--; if (ter != j) { pla[i][ter] = pla[i][j]; pla[i][j] = '.'; por = true; } } } }; } } for (int z = 0; z < wys; z++) { for (int x = 0; x < sze; x++) { cout << pla[z][x]; } cout << endl; } } |