#include <bits/stdc++.h>
using namespace std;
void wypisz(vector<string>& mapa, int n, int m){
for (int i = 0; i < n; i++){
cout << mapa[i] << "\n";
}
return ;
}
void przesun(vector<string>& mapa, int n, int m, int p){
vector<string> nowamapa;
string aha = "";
for (int i = 0; i < m; i++) aha.push_back('.');
for (int i = 0; i < n; i++) nowamapa.push_back(aha);
int ile = 0;
if (p == 0){ // gora
for (int j = 0; j < m; j++){
ile = 0;
for (int i = 0; i < n; i++){
if (mapa[i][j] != '.'){
nowamapa[ile][j] = mapa[i][j];
ile++;
}
}
}
}
if (p == 1){ // dol
for (int j = 0; j < m; j++){
ile = 0;
for (int i = n-1; i >= 0; i--){
if (mapa[i][j] != '.'){
nowamapa[n-ile-1][j] = mapa[i][j];
ile++;
}
}
}
}
if (p == 2){ // lewo
for (int i = 0; i < n; i++){
ile = 0;
for (int j = 0; j < m; j++){
if (mapa[i][j] != '.'){
nowamapa[i][ile] = mapa[i][j];
ile++;
}
}
}
}
if (p == 3){ // prawo
for (int i = 0; i < n; i++){
ile = 0;
for (int j = m-1; j >= 0; j--){
if (mapa[i][j] != '.'){
nowamapa[i][m-1-ile] = mapa[i][j];
ile++;
}
}
}
}
mapa = nowamapa;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
vector<string> mapa;
string s;
for (int i = 0; i < n; i++){
cin >> s;
mapa.push_back(s);
}
int k;
cin >> k;
cin >> s;
vector<char> posy;
for (int i = 0; i < k; i++){
if (i == k-1){
posy.push_back(s[i]);
continue;
}
if ((s[i] == 'G' || s[i] == 'D') && ((s[i+1] == 'G' || s[i+1] == 'D'))) continue;
if ((s[i] == 'L' || s[i] == 'P') && ((s[i+1] == 'L' || s[i+1] == 'P'))) continue;
posy.push_back(s[i]);
}
vector<char> posy2;
if (posy.size() <= 500) posy2 = posy;
else{
posy2.push_back(posy[0]);
posy2.push_back(posy[1]);
posy2.push_back(posy[posy.size()-2]);
posy2.push_back(posy[posy.size()-1]);
}
for (auto u: posy2){
if (u == 'G') przesun(mapa,n,m,0);
if (u == 'D') przesun(mapa,n,m,1);
if (u == 'L') przesun(mapa,n,m,2);
if (u == 'P') przesun(mapa,n,m,3);
}
wypisz(mapa,n,m);
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 | #include <bits/stdc++.h> using namespace std; void wypisz(vector<string>& mapa, int n, int m){ for (int i = 0; i < n; i++){ cout << mapa[i] << "\n"; } return ; } void przesun(vector<string>& mapa, int n, int m, int p){ vector<string> nowamapa; string aha = ""; for (int i = 0; i < m; i++) aha.push_back('.'); for (int i = 0; i < n; i++) nowamapa.push_back(aha); int ile = 0; if (p == 0){ // gora for (int j = 0; j < m; j++){ ile = 0; for (int i = 0; i < n; i++){ if (mapa[i][j] != '.'){ nowamapa[ile][j] = mapa[i][j]; ile++; } } } } if (p == 1){ // dol for (int j = 0; j < m; j++){ ile = 0; for (int i = n-1; i >= 0; i--){ if (mapa[i][j] != '.'){ nowamapa[n-ile-1][j] = mapa[i][j]; ile++; } } } } if (p == 2){ // lewo for (int i = 0; i < n; i++){ ile = 0; for (int j = 0; j < m; j++){ if (mapa[i][j] != '.'){ nowamapa[i][ile] = mapa[i][j]; ile++; } } } } if (p == 3){ // prawo for (int i = 0; i < n; i++){ ile = 0; for (int j = m-1; j >= 0; j--){ if (mapa[i][j] != '.'){ nowamapa[i][m-1-ile] = mapa[i][j]; ile++; } } } } mapa = nowamapa; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<string> mapa; string s; for (int i = 0; i < n; i++){ cin >> s; mapa.push_back(s); } int k; cin >> k; cin >> s; vector<char> posy; for (int i = 0; i < k; i++){ if (i == k-1){ posy.push_back(s[i]); continue; } if ((s[i] == 'G' || s[i] == 'D') && ((s[i+1] == 'G' || s[i+1] == 'D'))) continue; if ((s[i] == 'L' || s[i] == 'P') && ((s[i+1] == 'L' || s[i+1] == 'P'))) continue; posy.push_back(s[i]); } vector<char> posy2; if (posy.size() <= 500) posy2 = posy; else{ posy2.push_back(posy[0]); posy2.push_back(posy[1]); posy2.push_back(posy[posy.size()-2]); posy2.push_back(posy[posy.size()-1]); } for (auto u: posy2){ if (u == 'G') przesun(mapa,n,m,0); if (u == 'D') przesun(mapa,n,m,1); if (u == 'L') przesun(mapa,n,m,2); if (u == 'P') przesun(mapa,n,m,3); } wypisz(mapa,n,m); return 0; } |
English