#include <stdio.h> char lam[500][500]; int w, h, q; int main(int argc, char** argv) { scanf("%d %d", &h, &w); for(int y=0;y<h;y++) for(int x=0;x<w;x++) { char tmp; scanf(" %c", &tmp); if(tmp == '.') lam[y][x] = 0; else lam[y][x] = tmp; } scanf(" %d", &q); int nq = -1; char last = -1; char s1 = -1, s2 = -1; char ops[500000] = {0}; for(int i=0;i<q;i++) { char tmp; scanf(" %c", &tmp); if(tmp == s1 || tmp == s2) continue; if(tmp == 'L' || tmp =='P') { if(last == 'L' || last =='P') ops[nq] = tmp; else ops[++nq] = tmp; s1 = tmp; } if(tmp == 'G' || tmp =='D') { if(last == 'G' || last =='D') ops[nq] = tmp; else ops[++nq] = tmp; s2 = tmp; } last = tmp; /*if(!ops[0]) *ops = tmp; else { if(tmp == 'L' || tmp =='P') { if(*ops == 'L' || *ops =='P') ops[0] = tmp; else ops[1] = tmp; } if(tmp == 'G' || tmp =='D') if(*ops == 'G' || *ops =='D') ops[0] = tmp; else ops[1] = tmp; }*/ } // printf("%d\n", nq); for(int i=0;i<nq+1;i++) { int ind; //printf("C %d\n", ops[i]); switch(ops[i]) { case 'L': for(int i=0;i<h;i++) { ind = 0; for(int j=0;j<w;j++) { if(lam[i][j]) { if(j == ind) { ind++; continue; } lam[i][ind++] = lam[i][j]; lam[i][j] = 0; } } } break; case 'P': for(int i=0;i<h;i++) { ind = w-1; for(int j=w-1;j>=0;j--) { if(lam[i][j]) { if(j == ind) { ind--; continue; } lam[i][ind--] = lam[i][j]; lam[i][j] = 0; } } } break; case 'G': for(int i=0;i<w;i++) { ind = 0; for(int j=0;j<h;j++) { if(lam[j][i]) { if(j == ind) { ind++; continue; } lam[ind++][i] = lam[j][i]; lam[j][i] = 0; } } } break; case 'D': for(int i=0;i<w;i++) { ind = h-1; for(int j=h-1;j>=0;j--) { if(lam[j][i]) { if(j == ind) { ind--; continue; } lam[ind--][i] = lam[j][i]; lam[j][i] = 0; } } } break; } /*putchar(10); for(int i=0;i<h;i++) { for(int j=0;j<w;j++) printf("%c", !lam[i][j] ? '.' : lam[i][j]); putchar(10); }*/ } for(int i=0;i<h;i++) { for(int j=0;j<w;j++) printf("%c", !lam[i][j] ? '.' : lam[i][j]); putchar(10); } 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 135 136 137 138 | #include <stdio.h> char lam[500][500]; int w, h, q; int main(int argc, char** argv) { scanf("%d %d", &h, &w); for(int y=0;y<h;y++) for(int x=0;x<w;x++) { char tmp; scanf(" %c", &tmp); if(tmp == '.') lam[y][x] = 0; else lam[y][x] = tmp; } scanf(" %d", &q); int nq = -1; char last = -1; char s1 = -1, s2 = -1; char ops[500000] = {0}; for(int i=0;i<q;i++) { char tmp; scanf(" %c", &tmp); if(tmp == s1 || tmp == s2) continue; if(tmp == 'L' || tmp =='P') { if(last == 'L' || last =='P') ops[nq] = tmp; else ops[++nq] = tmp; s1 = tmp; } if(tmp == 'G' || tmp =='D') { if(last == 'G' || last =='D') ops[nq] = tmp; else ops[++nq] = tmp; s2 = tmp; } last = tmp; /*if(!ops[0]) *ops = tmp; else { if(tmp == 'L' || tmp =='P') { if(*ops == 'L' || *ops =='P') ops[0] = tmp; else ops[1] = tmp; } if(tmp == 'G' || tmp =='D') if(*ops == 'G' || *ops =='D') ops[0] = tmp; else ops[1] = tmp; }*/ } // printf("%d\n", nq); for(int i=0;i<nq+1;i++) { int ind; //printf("C %d\n", ops[i]); switch(ops[i]) { case 'L': for(int i=0;i<h;i++) { ind = 0; for(int j=0;j<w;j++) { if(lam[i][j]) { if(j == ind) { ind++; continue; } lam[i][ind++] = lam[i][j]; lam[i][j] = 0; } } } break; case 'P': for(int i=0;i<h;i++) { ind = w-1; for(int j=w-1;j>=0;j--) { if(lam[i][j]) { if(j == ind) { ind--; continue; } lam[i][ind--] = lam[i][j]; lam[i][j] = 0; } } } break; case 'G': for(int i=0;i<w;i++) { ind = 0; for(int j=0;j<h;j++) { if(lam[j][i]) { if(j == ind) { ind++; continue; } lam[ind++][i] = lam[j][i]; lam[j][i] = 0; } } } break; case 'D': for(int i=0;i<w;i++) { ind = h-1; for(int j=h-1;j>=0;j--) { if(lam[j][i]) { if(j == ind) { ind--; continue; } lam[ind--][i] = lam[j][i]; lam[j][i] = 0; } } } break; } /*putchar(10); for(int i=0;i<h;i++) { for(int j=0;j<w;j++) printf("%c", !lam[i][j] ? '.' : lam[i][j]); putchar(10); }*/ } for(int i=0;i<h;i++) { for(int j=0;j<w;j++) printf("%c", !lam[i][j] ? '.' : lam[i][j]); putchar(10); } return 0; } |