新手求找个错误
#include<stdio.h>#include<stdlib.h>
int queen_Count(int,int);
int queen[8][8] = {0};
int line[100] = {0};
int right[100] = {0};
int lift[100] = {0};
int p = 1;
int main()
{
int position1,position2;
position1 = 0;
position2 = 0;
queen_Count(position1,position2);
getchar();
}
int queen_Count(int position1,int position2)
{
int j;
int k;
if(p >= 9)
{
for(j = 0; j < 8;j++)
{
for(k = 0;k < 8;k++)
{
printf(" %d ",queen[j][k]);
}
printf("\n");
}
}
else
{
queen[position1][position2] = 1;
p++;
if(lift[position1 + position2] == 0 && right[position1 - position2 + 7] == 0 && line[position2] == 0)
{
lift[position1 + position2] = 1;
right[position1 - position2 + 7] = 1;
line[position2] = 1;
if(queen_Count(position1 + 1,1) || queen_Count(position1 + 1,2) || queen_Count(position1 + 1,3) || queen_Count(position1 + 1,4)||
queen_Count(position1 + 1,5) ||queen_Count(position1 + 1,6) || queen_Count(position1 + 1,7) ||queen_Count(position1 + 1,8))
{
return 1;
}
else
{
lift[position1 + position2] = 0;
right[position1 - position2 + 7] = 0;
line[position2] = 0;
queen[position1][position2] = 0;
p--;
return 0;
}
}
else
{
queen[position1][position2] = 0;
p--;
return 0;
}
}
}