Advertisement
Guest User

Permutari

a guest
Nov 21st, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. ifstream fin("permutari.in");
  5. ofstream fout("permutari.out");
  6. int x[20],n,c;
  7. void Afisare(int k)
  8. {
  9. for(int i=1;i<=n;i++)
  10. fout<<x[i]<<" ";
  11. fout<<'\n';
  12. }
  13. int Valid(int k)
  14. {
  15. for(int i=1;i<k;i++)
  16. if(x[i]==x[k])return 0;
  17. return 1;
  18. }
  19. void Back(int k)
  20. {
  21. for(int i=1;i<=n;i++)
  22. {
  23. x[k]=i;
  24. if(Valid(k))
  25. if(k==n)
  26. Afisare(k);
  27. else
  28. Back(k+1);
  29. }
  30. }
  31. int main()
  32. {
  33. fin>>n;
  34. Back(1);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement