SHARE
TWEET

Cifregen1

ToxicrewZeu Oct 10th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. /**
  5. 1. Stiva de lungime n
  6. 2. Pe stiva punem litere consecutive ale alfabetului
  7. 3. Validare: v[1]=v[n]='a'
  8. */
  9. char lit[]="abcdefghijklmopqrstuvwxyz";
  10. int n,st[27];
  11. void Afisare()
  12. {
  13.    for(int i=1;i<=n;i++)
  14.         cout<<lit[st[i]];
  15.    cout<<"\n";
  16. }
  17. int Modul(int x)
  18. {
  19.     if(x<0) x=-x;
  20.     return x;
  21. }
  22. int Valid(int top)
  23. {
  24.    if(top==n-1 and st[top]!= 1) return 0;
  25.    if(top==n and st[top]!=0) return 0;
  26.    if(top>1 and Modul(st[top]-st[top-1])!=1) return 0;
  27.    return 1;
  28. }
  29. void Back()
  30. {
  31.     int cand,top;
  32.     top=1;
  33.     st[top]=0;
  34.     top=2;
  35.     while(top>1)
  36.     {
  37.         cand=0;
  38.         while(!cand and st[top]<25)
  39.         {
  40.             st[top]++;
  41.             cand=Valid(top);
  42.         }
  43.         if(!cand) top--;
  44.         else if(top==n) Afisare();
  45.         else st[++top]=-1;
  46.     }
  47. }
  48. int main()
  49. {
  50.     cin>>n;
  51.     Back();
  52.     return 0;
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top