Just started to learn C + +, what's wrong with the code and you're welcome to point out
//the problem of n queens can be solved by modifying macros#defineMAX 8#defineABS (x) ((x>0)? ( x):-(x))classqueen{Private: intQueen[max]; Public: Queen (); intPlace (int); intAttack (int,int); intOutdata (); ~Queen ();}; Queen::queen () {//for (int i = 0; i < MAX; i++) queen[i] = 0;Std::cout <<"Hello,welcome to eight Queen"; Place (0);}//arrange the next queen .intQueen::P Lace (intp) { for(inti =0; I <8; i++) { if(!Attack (P, i)) {Queen[p]=i; if(p = = MAX-1) Outdata (); Else{Place (P+1); } } } return 0;}//determine if an attack has been received, return 1, or return 0intQueen::attack (intRowintCol) { intFlag =0; //I<row can be guaranteed not on the same line for(inti =0; I < row &&!flag; i++) { intInc_row = ABS (i-row); intInc_col = ABS (queen[i)-col); //determine if the same column, whether on a slashFlag = (Col = = Queen[i]) | | (Inc_col = =Inc_row); } returnFlag;}intQueen::outdata () { for(inti =0; i < MAX; i++) { for(intj =0; J < MAX; J + +) { if(j = = Queen[i]) std::cout <<"Q"; ElseStd::cout <<"-"; } std::cout<<"\ n"; } getchar (); return 0;} Queen::~Queen () {std::cout<<"End"<<Std::endl;}intMain () {Queen A; return 0;}
debugging, there will be a problem, always output results, after careful review of the code to see, due to recursive invocation, you can output all kinds of results, so you have to distinguish the results, adding getchar is to output a result
Question of the eight Queens