Advertisement
Wooph

Regine1

Feb 25th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include<fstream>
  2. #include <iostream>
  3. #include<cstdlib>
  4. using namespace std;
  5. int st[10],n,k;
  6. int valid(int niv)
  7. {
  8.     int i;
  9.     for(i=1; i<niv; i++)
  10.     {
  11.         if(st[i]==st[niv])
  12.             return 0;
  13.             if(abs(st[i]-st[niv])==(niv-i))
  14.                 return 0;
  15.     }
  16.  
  17.     return 1;
  18.  
  19. }
  20. void afisare_stiva()
  21. { k++;
  22.     int i,j;
  23.     for(i=1; i<=n; i++)
  24.     {
  25.         for(j=1;j<=n;j++)
  26.             if(j==st[i])
  27.             cout<<'*';
  28.         else
  29.         cout<<'-';
  30.     cout<<endl;
  31.     }
  32. }
  33. void back(int nivel)
  34. {
  35.     if(nivel>n&&k==0) afisare_stiva();
  36.     else
  37.     {
  38.         for(int i=1; i<=n; i++)
  39.         {
  40.             st[nivel]=i;
  41.             if(valid(nivel)) back(nivel+1);
  42.         }
  43.     }
  44. }
  45. int main ()
  46. {
  47. cin>>n;
  48. back(1);
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement