Advertisement
STANAANDREY

permutari

Jun 29th, 2019
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int N, fol[26];
  5.  
  6. void gen(int lg, char sir[277]) {
  7.   if (lg == N + 1) {
  8.     for (int i = 1; i <= N; ++i)
  9.       cout<<sir[i];
  10.     cout<<"\n";
  11.     return;
  12.   }
  13.   for (char c = 'a'; c < 'a' + N; ++c)
  14.     if (fol[c - 'a'] == 0) {
  15.       sir[lg] = c;
  16.       fol[c - 'a'] = 1;
  17.       gen(lg + 1, sir);
  18.       fol[c - 'a'] = 0;
  19.       // La intoarcerea din recursivitate este important sa marcam ca nu mai
  20.       // folosim litera curenta
  21.     }
  22. }
  23.  
  24. int main()
  25. {
  26.     cin>>N;
  27. char s[]="";
  28. gen(1,s);
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement