#include <stdio.h>
#include <stdlib.h>static char Queen[8][8];static int a[8];static int b[15];static int c[15];static int iQueenNum = 0;//record statevoid qu(int i);int main(int argc, char *argv[])
{ //init int line, column; for(line = 0;line < 8;line++) { a[line] = 0; for(column = 0;column < 8;column++) { Queen[line][column] = '*'; } } for(line = 0;line < 15;line++) { b[line] = c[line] = 0;; } qu(0); system("PAUSE"); return 0;}void qu(int i)//columm
{ int iColumn; for (iColumn = 0;iColumn < 8;iColumn++) { //no conflict if(a[iColumn]==0 && b[i-iColumn+7]==0 && c[i+iColumn]==0) { //put a queen Queen[i][iColumn] = '@'; //record confilict a[iColumn] = 1; b[i-iColumn+7] = 1; c[i+iColumn] = 1; if(i<7) qu(i+1); else//out put { int line, column; printf("第%d种状态为:\n", ++iQueenNum); for(line = 0;line < 8;line++) { for(column = 0;column < 8;column++) { printf("%c ", Queen[line][column]); } printf("\n"); } printf("\n\n"); } //back Queen[i][iColumn] = '*'; a[iColumn] = 0; b[i-iColumn+7] = 0; c[i+iColumn] = 0; } }}