Advertisement
JDzheng005

Untitled

Jan 17th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. using namespace std;
  2.  
  3. int x[8];
  4. void queue();
  5. bool place(int k);
  6. int main(){
  7.  
  8. queue();
  9.  
  10. }
  11. bool place(int k)
  12. {
  13. for(int j=1;j<k;j++){
  14. if(x[k]-x[j] == k -j || x[j] == x[k] || x[k]-x[j] == j-k )
  15. return false;
  16. return true;
  17. }
  18.  
  19. }
  20. void queue () {
  21.  
  22. int i,k;
  23. for(i = 1; i <= 8; i++){
  24. x[i]=0;
  25.  
  26. }
  27. k=1;
  28. while(k>=1 && !place(k)){
  29. cout << "succed";
  30. x[k]=x[k]+1;
  31. if(x[k] <= 8 && k==8){
  32.  
  33. for (i=1; i<=8;i++){
  34. cout << x[i];
  35. cout << "\n";
  36. }
  37.  
  38. }
  39. else if (x[k]<= 8 && k < 8)
  40. k = k + 1;
  41. else
  42. {
  43. x [k] = 0;
  44. k = k-1;
  45.  
  46. }
  47.  
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement