たぶん、質問文の最初に「C言語」ってあるから、タグが間違いでC言語だと思います。
C
1#include <stdio.h>
2
3#define CELL_START 3
4#define CELL_END 8
5int main(void)
6{
7 int a[8][8];
8
9 for (int y = 0; y < CELL_END; y++) {
10 for (int x = 0; x < CELL_END; x++) {
11 a[y][x] = 0;
12 }
13 }
14
15 for (int x = CELL_START; x < CELL_END; x++) {
16 a[7][x] = 1;
17 }
18
19 a[3][4] = 1;
20 a[3][5] = 1;
21 a[3][6] = 1;
22 a[4][3] = 1;
23 a[4][7] = 1;
24 a[5][5] = 1;
25 a[5][6] = 1;
26 a[6][4] = 1;
27
28 for (int y = CELL_START; y < CELL_END; y++) {
29 int cnt = 0;
30 for (int x = CELL_START; x < CELL_END; x++) {
31 if (a[y][x] == 1) {
32 cnt++;
33 } else if (cnt > 0) {
34 for (int x2 = 0; x2 < CELL_START; x2++) {
35 if (a[y][x2] == 0) {
36 a[y][x2] = cnt;
37 cnt = 0;
38 break;
39 }
40 }
41 }
42 }
43 if (cnt > 0) {
44 for (int x2 = 0; x2 < CELL_START; x2++) {
45 if (a[y][x2] == 0) {
46 a[y][x2] = cnt;
47 cnt = 0;
48 break;
49 }
50 }
51 }
52 }
53
54 for (int x = CELL_START; x < CELL_END; x++) {
55 int cnt = 0;
56 for (int y = CELL_START; y < CELL_END; y++) {
57 if (a[y][x] == 1) {
58 cnt++;
59 } else if (cnt > 0) {
60 for (int y2 = 0; y2 < CELL_START; y2++) {
61 if (a[y2][x] == 0) {
62 a[y2][x] = cnt;
63 cnt = 0;
64 break;
65 }
66 }
67 }
68 }
69 if (cnt > 0) {
70 for (int y2 = 0; y2 < CELL_START; y2++) {
71 if (a[y2][x] == 0) {
72 a[y2][x] = cnt;
73 cnt = 0;
74 break;
75 }
76 }
77 }
78 }
79
80 for (int y = CELL_START; y < CELL_END; y++) {
81 while (a[y][CELL_START - 1] == 0) {
82 for (int x = CELL_START - 2; x >= 0; x--) {
83 a[y][x + 1] = a[y][x];
84 }
85 a[y][0] = 0;
86 }
87 }
88
89 for (int x = CELL_START; x < CELL_END; x++) {
90 while (a[CELL_START - 1][x] == 0) {
91 for (int y = CELL_START - 2; y >= 0; y--) {
92 a[y + 1][x] = a[y][x];
93 }
94 a[0][x] = 0;
95 }
96 }
97
98 for (int y = 0; y < CELL_END; y++) {
99 for (int x = 0; x < CELL_END; x++) {
100 if (y < CELL_START || x < CELL_START) {
101 if (a[y][x] > 0) {
102 printf(" %d", a[y][x]);
103 } else {
104 printf(" ");
105 }
106 continue;
107 }
108
109 if (a[y][x] == 1) {
110 printf(" O");
111 } else {
112 printf(" ");
113 }
114 }
115 putchar('\n');
116 }
117
118 return 0;
119}
terminal
1$ ilogic
2 1 1
3 1 1 1 1 1
4 1 2 1 1 1
5 3 O O O
6 1 1 O O
7 2 O O
8 1 O
9 5 O O O O O
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/08/05 15:38
2020/08/05 15:58 編集
2020/08/05 16:20