• API
• FAQ
• Tools
• Trends
• Archive
daily pastebin goal
28%
SHARE
TWEET

# Untitled

a guest Jun 19th, 2017 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2. # include <stdio.h>
3. # include <stdlib.h>
4. # include <time.h>
5.
6. using namespace std;
7.
8. int N; // For the Number of Rows
9. int mark;
10. void printposition(int array[]); //print final solution
11. void Positions(int a[],int x,int y); //Recursion
12.
13. void printposition (int array[]) // Each call gets its own count
14. {
15.      int b;
16.      int choose;
17.      static int counting = 0;
18.      counting ++;
19.      printf("\nSolution Number #%d: ", counting); //%d
20.      for(b=0;b<N;b++)
21.      printf("(%d,%d) ",b+1,array[b]+1);
22.      if(counting%5==0) //every 5 solution
23.      {
24.       cout << "\nType 0 to exit, 1 to Continue Solving" <<endl;
25.       scanf("%d",&choose);
26.      if(choose==0) exit(0);
27.              };
28. }
29.
30. //void Positions(int a1[],int column,int row)
31. //{ int count1,count2;
32. //  a1[column]=row;
33. //  if(column==N-1)
34. //  { printposition(a1) ;
35. //    return;
36.   //         };
37.  // for(count1=0;count1<N;)
38. //  {      /* This Loop Finds Suitable Column Numbers , in the NEXT ROW */
39.  //  for(count2=0;count2<=column;count2++)
40.  //  if(a1[count2]==count1 || (column+1-count2)*(column+1-count2)==(count1-a1[count2])*(count1-a1[count2]))
41.  //  goto miss1;
42.  //  Positions(a1,column+1,count1);
43.  //  miss1:
44.  //  count1++;
45.  //  }
46. //}
47.
48. void Positions(int a1[],int column,int row)
49. { int count1,count2;
50.   bool miss = false;
51.   a1[column]=row;
52.   if(column==N-1)
53.     { printposition(a1) ;
54.     return;
55.            };
56.   for(count1=0;count1<N;)
57.   {      /* This Loop Finds Suitable Column Numbers , in the NEXT ROW */
58.    for(count2=0;count2<=column;count2++)
59.    {
60.       if(a1[count2]==count1 || (column+1-count2)*(column+1-count2)==(count1-a1[count2])*(count1-a1[count2]))
61.       {
62.          miss = true;
63.
64.       }
65.    }
66.    if(!miss)
67.    {
68.       Positions(a1,column+1,count1);
69.    }
70.    count1++;
71.    }
72. }
73.
74. int main()
75. {
76.     int *a;
77.     int count=0;
78.
79.  printf ("\nInput Size of Chessboard: ");
80.  scanf("%d",&N);
81.  a=(int *)(malloc(sizeof(int)*N));
82.  for(count=0;count<N;count++)
83.  Positions(a,0,count);
84.
85. }
RAW Paste Data
Top