teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

ヒントが逆順に表示されていたのを修正

2020/08/05 15:57

投稿

Daregada
Daregada

スコア11990

answer CHANGED
@@ -5,7 +5,6 @@
5
5
 
6
6
  #define CELL_START 3
7
7
  #define CELL_END 8
8
-
9
8
  int main(void)
10
9
  {
11
10
  int a[8][8];
@@ -35,7 +34,7 @@
35
34
  if (a[y][x] == 1) {
36
35
  cnt++;
37
36
  } else if (cnt > 0) {
38
- for (int x2 = CELL_START - 1; x2 >= 0; x2--) {
37
+ for (int x2 = 0; x2 < CELL_START; x2++) {
39
38
  if (a[y][x2] == 0) {
40
39
  a[y][x2] = cnt;
41
40
  cnt = 0;
@@ -45,7 +44,7 @@
45
44
  }
46
45
  }
47
46
  if (cnt > 0) {
48
- for (int x2 = CELL_START - 1; x2 >= 0; x2--) {
47
+ for (int x2 = 0; x2 < CELL_START; x2++) {
49
48
  if (a[y][x2] == 0) {
50
49
  a[y][x2] = cnt;
51
50
  cnt = 0;
@@ -61,7 +60,7 @@
61
60
  if (a[y][x] == 1) {
62
61
  cnt++;
63
62
  } else if (cnt > 0) {
64
- for (int y2 = CELL_START - 1; y2 >= 0; y2--) {
63
+ for (int y2 = 0; y2 < CELL_START; y2++) {
65
64
  if (a[y2][x] == 0) {
66
65
  a[y2][x] = cnt;
67
66
  cnt = 0;
@@ -71,7 +70,7 @@
71
70
  }
72
71
  }
73
72
  if (cnt > 0) {
74
- for (int y2 = CELL_START - 1; y2 >= 0; y2--) {
73
+ for (int y2 = 0; y2 < CELL_START; y2++) {
75
74
  if (a[y2][x] == 0) {
76
75
  a[y2][x] = cnt;
77
76
  cnt = 0;
@@ -81,6 +80,24 @@
81
80
  }
82
81
  }
83
82
 
83
+ for (int y = CELL_START; y < CELL_END; y++) {
84
+ while (a[y][CELL_START - 1] == 0) {
85
+ for (int x = CELL_START - 2; x >= 0; x--) {
86
+ a[y][x + 1] = a[y][x];
87
+ }
88
+ a[y][0] = 0;
89
+ }
90
+ }
91
+
92
+ for (int x = CELL_START; x < CELL_END; x++) {
93
+ while (a[CELL_START - 1][x] == 0) {
94
+ for (int y = CELL_START - 2; y >= 0; y--) {
95
+ a[y + 1][x] = a[y][x];
96
+ }
97
+ a[0][x] = 0;
98
+ }
99
+ }
100
+
84
101
  for (int y = 0; y < CELL_END; y++) {
85
102
  for (int x = 0; x < CELL_END; x++) {
86
103
  if (y < CELL_START || x < CELL_START) {
@@ -108,8 +125,8 @@
108
125
  ```terminal
109
126
  $ ilogic
110
127
  1 1
128
+ 1 1 1 1 1
111
129
  1 2 1 1 1
112
- 1 1 1 1 1
113
130
  3 O O O
114
131
  1 1 O O
115
132
  2 O O