我承认这个判断斜角的方法不好,但是我没有好的方法
sh-5.2$ cat main.c
#include <stdio.h>
#include <stdbool.h>
void display(bool array) {
for(size_t y = 0; y < 6; ++y) {
for(size_t x = 0; x < 6; ++x) {
printf("%d ", array);
}
puts("");
}
puts("");
}
bool check(bool array) {
for(size_t y = 0; y < 6; ++y) {
size_t sum = 0;
for(size_t x = 0; x < 6; ++x) {
sum += array;
}
if(sum > 1) return false;
}
for(size_t x = 0; x < 6; ++x) {
size_t sum = 0;
for(size_t y = 0; y < 6; ++y) {
sum += array;
}
if(sum > 1) return false;
}
for(size_t y = 0; y < 11; ++y) {
size_t sum = 0;
for(size_t x = 0, ny = y; x < 6; ++x, ++ny) {
if(ny < 5) continue;
if(ny >= 11) continue;
sum += array;
}
if(sum > 1) return false;
}
for(size_t y = 0; y < 11; ++y) {
size_t sum = 0;
for(size_t x = 5, ny = y; x < 6; --x, ++ny) {
if(ny < 5) continue;
if(ny >= 11) continue;
sum += array;
}
if(sum > 1) return false;
}
return true;
}
void chess(bool array, size_t y) {
if(y == 6) {
if(check(array)) display(array);
return;
}
for(size_t x = 0; x < 6; ++x) {
array = true;
chess(array, y + 1);
array = false;
}
}
int main(void) {
bool array = {false};
chess(array, 0);
return 0;
}
sh-5.2$ ./main
0 1 0 0 0 0
0 0 0 1 0 0
0 0 0 0 0 1
1 0 0 0 0 0
0 0 1 0 0 0
0 0 0 0 1 0
0 0 1 0 0 0
0 0 0 0 0 1
0 1 0 0 0 0
0 0 0 0 1 0
1 0 0 0 0 0
0 0 0 1 0 0
0 0 0 1 0 0
1 0 0 0 0 0
0 0 0 0 1 0
0 1 0 0 0 0
0 0 0 0 0 1
0 0 1 0 0 0
0 0 0 0 1 0
0 0 1 0 0 0
1 0 0 0 0 0
0 0 0 0 0 1
0 0 0 1 0 0
0 1 0 0 0 0
sh-5.2$
听不懂c/c++ 只会python {:7_113:} 帖子排版不错滴,中英文标点符号能改进更棒!! 阿萨德 感谢讲解 学习编程中的Ben 发表于 2024-2-4 21:12
@yinda_peng @人造人 @sfqxx @歌者文明清理员 @alwonwang @zhangchenyvn @zhangjinxuan
新年快乐 good {:9_236:} 感谢感谢
{:10_275:} 加油
学习一下
页:
1
[2]