user-0 提问: 新手做八皇后问题遇到了问题，请教大佬

回复:
user: user-1
content: #include <stdio.h> #include <stdlib.h> #include <string.h> static int count = 0; static int number = 0; static char buffer[8][8]; static void output() {         printf("********** %d ***********\n", count);         for(int i=0;i<8;i++)         {                 for(int j=0;j<8;j++)                 {                         if(buffer[i][j] == 1)                                 printf("# ");                         else                                 printf(". ");                 }                 printf("\n");         } } int check(int x, int y) {         for(int i=1; i<=x; i++)         {                 //the left slash can't has another value                 if(y-i >= 0)                 {                         if(buffer[x-i][y-i] == 1 )                                 return 1;                 }                 //the right slash can't has another value                 if(y+i < 8)                 {                         if(buffer[x-i][y+i] == 1)                                 return 1;                 }                 //the y line  can't has another value                 if(buffer[x-i][y] == 1)                         return 1;         }         return 0; } int check_line(int x) {         //means to the end         if(x == 8)                 return 0;         int ret = 0;         for(int i=0;i<8;i++)         {                 //check if the current point satisfy the condition                 if(check(x, i) == 0)                 {                         //if satisfy the condition, set value.                         buffer[x][i] = 1;                         //from current row, check the next row to find out if                          //there has a point that satisfy the condition.                         if(check_line(x+1) == 0)                         {                                 //if yes.that means we found an situation                                 count++;                                 output();                         }                         // if not. reset the value. and check next point with the same row                         buffer[x][i] = 0;                 }                 else                         ret = 1;         }         if(ret == 1)                 return 1;         return 0; } int eight_queue(int x, int y) {         //set the first point value,and get other valid value from it.         for(int i=0; i<8; i++)         {                 buffer[x][i] = 1;                 //main function. check each row to find out the right point                 check_line(x+1);                 memset(buffer, 0, sizeof(buffer));         } } int main(int argc, char *argv[]) {         //start from the first row         eight_queue(0,0);         return 0; }

user: user-2
content: 仅供参考：#include <stdio.h> int d[8][8]; int n; void queen8(int L) {     int x,y;      if (8==L) {         n++;         printf("%d\n",n);         for (y=0;y<8;y++) {             for (x=0;x<8;x++) { //              printf("%d",d[y][x]);                 if (d[y][x]) printf("■");                 else         printf("□");             }             printf("\n");         }         return;     }     for (x=0;x<8;x++) {         for (y=0;y<L;y++) {             if  (              d[y][x      ]              || (x-(L-y)>=0 && d[y][x-(L-y)])              || (x+(L-y)< 8 && d[y][x+(L-y)]))                 break;         }         if (y>=L) {             d[L][x]=1;             queen8(L+1);             d[L][x]=0;         }     } } int main() {     int y,x;     for (y=0;y<8;y++) {         for (x=0;x<8;x++) {             d[y][x]=0;         }     }     queen8(0);     return 0; }  “给定一个小点的输入，完整单步跟踪(同时按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史)一遍。”是理解递归函数工作原理的不二法门！ 递归函数关注以下几个因素 ·退出条件 ·参数有哪些 ·返回值是什么 ·局部变量有哪些 ·全局变量有哪些 ·何时输出 ·会不会导致堆栈溢出

user: user-3
content: 单步跟踪程序运行，观察变量变化情况与你期望的是否一致，分析原因