Guest User

Untitled

a guest
Oct 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. bool ok(int q[], int c){
  6. for ( int i=0; i<c;i++){
  7. if (q[i]==q[c] || ((c-i)==abs(q[c]-q[i])))
  8. return false;
  9. }
  10. return true;
  11. }
  12. void print (int q[]){
  13. static int numSolutions=0;
  14. cout<<"Solution "<<++numSolutions<<":n";
  15. for (int i=0;i<8;i++){
  16. cout <<q[i]<<" ";
  17. }
  18. cout<<endl;
  19. }
  20. int main()
  21. {
  22. int q[8], c=0;
  23. q[0]=0;
  24. while (c>=0){
  25. c++;
  26. if(c==8)
  27. q[c]=-1;
  28. else if(c==-1)
  29. return 0;
  30. while (c>=0){
  31. q[c]++;
  32. if (q[c]==8){
  33. c--;
  34. if (c==-1) break;
  35. }
  36. if (ok(q,c)==true)break;
  37. }
  38. }
  39.  
  40.  
  41. }
Add Comment
Please, Sign In to add comment