Advertisement
STANAANDREY

permutari numere

Jul 27th, 2019
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 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, int 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 (int c = 1; c < 1 + N; ++c)
  14.     if (fol[c] == 0) {
  15.       sir[lg] = c;
  16.       fol[c] = 1;
  17.       gen(lg + 1, sir);
  18.       fol[c] = 0;
  19.     }
  20.     return;
  21. }
  22.  
  23. int main()
  24. {
  25.     cin>>N;
  26.     int s[100];
  27.     gen(1,s);
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement