Advertisement
Eddie_1337

2/308

May 24th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream.h>
  2. int n; char v[20];
  3. int cont(int k){
  4.     for(int i=1;i<k;i++){
  5.         if(v[i]==v[k])
  6.             return 0;
  7.         if(v[k-1]==v[k]-1 || v[k-1]==v[k]+1)
  8.             continue;
  9.         else
  10.             return 0;
  11.     }
  12.     return 1;
  13. }
  14. int sol(int k){
  15.     return k==n;
  16. }
  17. int afisare(int k){
  18.     for(int i=1;i<=k;i++)
  19.         cout<<v[i];
  20.     cout<<" ";
  21. }
  22. int back(int k){
  23.     for(int i=65;i<=90;i++){
  24.         v[k]=(char)i;
  25.         if(cont(k))
  26.             if(sol(k))
  27.                 afisare(k);
  28.             else
  29.                 back(k+1);
  30.     }
  31. }
  32. int main (){
  33.     cin>>n;
  34.     back(1);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement