This commit is contained in:
unlockable
2022-10-27 14:03:17 +08:00
parent bf3b5851d3
commit 6e32ca4ba1
10 changed files with 257 additions and 0 deletions

35
06/Optional04.c Normal file
View File

@@ -0,0 +1,35 @@
#include <stdio.h>
int hats[6] = {0};
int count = 0;
void nextChild(int childIndex, int whiteRemaining, int blackremaining) {
int i;
if (childIndex == 6) {
count++;
for (int i = 0; i < 6; i++) {
if (hats[i] == -1) {
printf("White");
}
else {
printf("Black");
}
printf("\t");
}
printf("\n");
}
if (whiteRemaining > 0) {
hats[childIndex] = -1;
nextChild(childIndex + 1, whiteRemaining - 1, blackremaining);
}
if (blackremaining > 0) {
hats[childIndex] = 1;
nextChild(childIndex + 1, whiteRemaining, blackremaining - 1);
}
}
int main() {
nextChild(0, 3, 3);
printf("Total: %d", count);
return 0;
}