Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- bool ok(int q[], int c){
- for ( int i=0; i<c;i++){
- if (q[i]==q[c] || ((c-i)==abs(q[c]-q[i])))
- return false;
- }
- return true;
- }
- void print (int q[]){
- static int numSolutions=0;
- cout<<"Solution "<<++numSolutions<<":n";
- for (int i=0;i<8;i++){
- cout <<q[i]<<" ";
- }
- cout<<endl;
- }
- int main()
- {
- int q[8], c=0;
- q[0]=0;
- while (c>=0){
- c++;
- if(c==8)
- q[c]=-1;
- else if(c==-1)
- return 0;
- while (c>=0){
- q[c]++;
- if (q[c]==8){
- c--;
- if (c==-1) break;
- }
- if (ok(q,c)==true)break;
- }
- }
- }
Add Comment
Please, Sign In to add comment