Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int x[101], n;
- int e_bun(int k)
- {
- for(int i=1; i<=k-1; i++)
- if(x[i]==x[k] || abs(i-k)==abs(x[i]-x[k]))
- return 0;
- return 1;
- }
- void afis(int k)
- {
- int i, j;
- for(i=1; i<=k; i++)
- {
- for(j=1; j<=k; j++)
- if(j==x[i])
- cout<<'D'<<' ';
- else
- cout<<'#'<<' ';
- cout<<'\n';
- }
- }
- void back()
- {
- int k=1;
- x[k]=0;
- while(k>0)
- {
- if(x[k]<n)
- {
- x[k]++;
- if(e_bun(k))
- if(k==n)
- {
- afis(k);
- cout<<'\n';
- }
- else
- {
- k++;
- x[k]=0;
- }
- }
- else
- k--;
- }
- }
- int main()
- {
- cin>>n;
- back();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment