Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- int x[8];
- void queue();
- bool place(int k);
- int main(){
- queue();
- }
- bool place(int k)
- {
- for(int j=1;j<k;j++){
- if(x[k]-x[j] == k -j || x[j] == x[k] || x[k]-x[j] == j-k )
- return false;
- return true;
- }
- }
- void queue () {
- int i,k;
- for(i = 1; i <= 8; i++){
- x[i]=0;
- }
- k=1;
- while(k>=1 && !place(k)){
- cout << "succed";
- x[k]=x[k]+1;
- if(x[k] <= 8 && k==8){
- for (i=1; i<=8;i++){
- cout << x[i];
- cout << "\n";
- }
- }
- else if (x[k]<= 8 && k < 8)
- k = k + 1;
- else
- {
- x [k] = 0;
- k = k-1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement