Wooph

CifreGen5

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