Untitled
unknown
c_cpp
3 years ago
3.9 kB
5
Indexable
#include <stdio.h> int n, m; int i, j, k; char in[45][45] = {'\0'}, out[45][45] = {'\0'}; int main(void) { int flag = 0; scanf("%d %d", &n, &m); for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { scanf(" %c", &in[i][j]); out[i][j] = in[i][j]; } } int temp = 0, steps = 45; for (j = 0; j < m; j++) { flag = 0; for (i = n - 1; i >= 0 && flag == 0; i--) { temp = 0; if (in[i][j] == 'o') { flag = 1; if (i == n - 1) steps = 0; else { for (k = i + 1; k < n; k++) { if (in[k][j] == 'x' && k == i + 1) { steps = 0; break; } if (in[k][j] == '.') temp++; else break; } } if (temp < steps && temp != 0) steps = temp; } } } /* for (i = 0; i < n; i++) { //算掉下來幾步 for (j = 0; j < m; j++) { temp = 0; if (in[i][j] == 'o') { for (k = (i + 1); k < n; k++) { if (in[k][j] == '.') { temp++; } else { break; } } if (temp < steps && temp != 0) steps = temp; break; } } } */ for (i = n - 1; i >= 0; i--) { //掉下來然後變成x for (j = 0; j < m; j++) { if (in[i][j] == 'o') { out[i][j] = '.'; out[i + steps][j] = 'x'; } } } for (i = (n - 1); i >= 0; i--) { //刪掉滿的行 temp = 0; for (j = 0; j < m; j++) { if (out[i][j] != '.') { temp++; if (temp == m) { for (k = 0; k < m; k++) { out[i][k] = '.'; } } } else break; } } /* for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { printf("%c", out[i][j]); } printf("\n"); } */ temp = 0; for (i = (n - 1); i >= 0; i--) { flag = 0; for (j = 0; j < m; j++) { if (out[i][j] != '.') { flag = 1; break; } } if (flag == 1 && i < n - 1 - temp) { for (j = 0; j < m; j++) { out[n - 1 - temp][j] = out[i][j]; if (n - 1 - temp != i) out[i][j] = '.'; } } if (flag == 1) temp++; } for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { printf("%c", out[i][j]); } printf("\n"); } return 0; } /* # Sample Input 1 8 9 ..o...... .oo...... ..o...... ......... ......... x..xxxxxx x..xxxxxx xx.xxxxxx # Sample Input 2 11 9 ..o...... ..o...... ..o...... ..o...... ......... ......... .xx...... xx.xxxxxx xx.xxx.xx x..xxxxxx xx.xxxxxx 11 9 ..o...... ..o...... ..o...... ..o...... ......... ......... ......... xx.xxx.xx xx.xxxxxx x..xxxxxx xx.xxxxxx 11 9 ..o...... ..o...... ..o...... ..o...... ..o...... ..o...... ..o...... xxoxxxxxx xxoxxx.xx x.oxxxxxx xxoxxxxxx # Sample Input 3 8 7 ....... ...oo.. ..oo... ..o.... ....... .x..... xx.xxxx x.xxxxx 8 7 ....... .x.oo.. .xoo... .xo.... .x..... .x..... xx.xxxx x.xxxxx 8 7 ....... .xxxx.. .xoo... .xo.... .x..... .x..... xx.xxxx x.xxxxx */
Editor is loading...