#include <iostream> #include <vector> #include <map> using namespace std; vector<string> rotate(vector<string>& v, char d) { vector<string> u(v.size(), string(v[0].size(), '.')); if (d == 'L') { for (int i = 0, k = 0; i < v.size(); i++, k = 0) { for (int j = 0; j < v[0].size(); j++) { if(v[i][j] != '.') { u[i][k++] = v[i][j]; } } } } else if(d == 'P') { for (int i = 0, k = v[0].size() - 1; i < v.size(); i++, k = v[0].size() - 1) { for (int j = v[0].size() - 1; j >= 0; j--) { if(v[i][j] != '.') { u[i][k--] = v[i][j]; } } } } else if(d == 'G') { for (int j = 0, k = 0; j < v[0].size(); j++, k = 0) { for (int i = 0; i < v.size(); i++) { if(v[i][j] != '.') { u[k++][j] = v[i][j]; } } } } else if(d == 'D') { for (int j = 0, k = v.size() - 1; j < v[0].size(); j++, k = v.size() - 1) { for (int i = v.size() - 1; i >= 0; i--) { if(v[i][j] != '.') { u[k--][j] = v[i][j]; } } } } return u; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m, k; string s, r; cin >> n >> m; vector<string> v(n), w; for (string& c: v) cin >> c; cin >> k; cin >> s; map<char, char> x; x = {{'L', 'P'}, {'P', 'L'}, {'D', 'G'}, {'G', 'D'}}; for(int i = 0; i < k; i++) { bool f = r.empty(); while(!f) { if(r.back() == s[i] || (r.size() >= 2 && r[r.size() - 2] == s[i])) break; else if(r.back() == x[s[i]]) { r.pop_back(); f = r.empty(); } else f = true; } if(f) r.push_back(s[i]); } v = rotate(v, r[0]); if(r.size() >= 2) { v = rotate(v, r[1]); w = v; } for(int i = 2; i < r.size(); i++) { v = rotate(v, r[i]); if(v == w && r[i] == r[1]) i = (r.size() - 2) / (i - 1) * (i - 1) + 1; } for (int i = 0; i < v.size(); i++) { for (int j = 0; j < v[0].size(); j++) cout << v[i][j]; cout << "\n"; } return 21/37; }
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 | #include <iostream> #include <vector> #include <map> using namespace std; vector<string> rotate(vector<string>& v, char d) { vector<string> u(v.size(), string(v[0].size(), '.')); if (d == 'L') { for (int i = 0, k = 0; i < v.size(); i++, k = 0) { for (int j = 0; j < v[0].size(); j++) { if(v[i][j] != '.') { u[i][k++] = v[i][j]; } } } } else if(d == 'P') { for (int i = 0, k = v[0].size() - 1; i < v.size(); i++, k = v[0].size() - 1) { for (int j = v[0].size() - 1; j >= 0; j--) { if(v[i][j] != '.') { u[i][k--] = v[i][j]; } } } } else if(d == 'G') { for (int j = 0, k = 0; j < v[0].size(); j++, k = 0) { for (int i = 0; i < v.size(); i++) { if(v[i][j] != '.') { u[k++][j] = v[i][j]; } } } } else if(d == 'D') { for (int j = 0, k = v.size() - 1; j < v[0].size(); j++, k = v.size() - 1) { for (int i = v.size() - 1; i >= 0; i--) { if(v[i][j] != '.') { u[k--][j] = v[i][j]; } } } } return u; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m, k; string s, r; cin >> n >> m; vector<string> v(n), w; for (string& c: v) cin >> c; cin >> k; cin >> s; map<char, char> x; x = {{'L', 'P'}, {'P', 'L'}, {'D', 'G'}, {'G', 'D'}}; for(int i = 0; i < k; i++) { bool f = r.empty(); while(!f) { if(r.back() == s[i] || (r.size() >= 2 && r[r.size() - 2] == s[i])) break; else if(r.back() == x[s[i]]) { r.pop_back(); f = r.empty(); } else f = true; } if(f) r.push_back(s[i]); } v = rotate(v, r[0]); if(r.size() >= 2) { v = rotate(v, r[1]); w = v; } for(int i = 2; i < r.size(); i++) { v = rotate(v, r[i]); if(v == w && r[i] == r[1]) i = (r.size() - 2) / (i - 1) * (i - 1) + 1; } for (int i = 0; i < v.size(); i++) { for (int j = 0; j < v[0].size(); j++) cout << v[i][j]; cout << "\n"; } return 21/37; } |