八皇后问题代码 那位大虾帮修改一下
李万鹏 2010-01-24 08:16:46 #include <stdio.h>
#include <math.h>
#include <stdlib.h>
struct Node{
int x;
int y;
};
int main(){
int i,j;
int a[8][8];
Node stack[8];
int top = -1, bottom = -1;
for( i = 0; i < 8; i++)
for( j = 0; j < 8; j++){
while( bottom <= top ){
if(i != stack[bottom].x && j != stack[bottom].y && (abs( i - stack[bottom].x) != abs(j - stack[bottom].y))){
bottom++;
continue;
}
else
break;
}
if(bottom > top)
stack[++top] = a[i][j];
else
top--;
}
}
for( i = 0; i < 8; i++)
printf("(%d,%d)",stack[i].x,stack[i].y);
system("pause");
return 0;
}