Advertisement
heian

Untitled

May 18th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("date.in");
  6. ofstream fout("date.out");
  7.  
  8. int n;
  9. int st[20];
  10.  
  11. void Afisare()
  12. {
  13. int i;
  14. for(i=1;i<=n;++i)
  15. fout<<st[i]<<" ";
  16. fout<<"\n";
  17. }
  18.  
  19. void Back(int k)
  20. {
  21. if(k==n+1)
  22. Afisare();
  23. int i;
  24. for(i=1;i<=n;i++)
  25. {
  26. //incerc sa generez toate permutarile care il au pe pozitia
  27. //k pe i
  28. //verific daca i-ul este disponibil(nu mai apare in permutarea actuala)
  29. bool disponibil=true;
  30. int j;
  31. for(j=1;j<k;j++)
  32. if(st[j]==i)
  33. disponibil=false;
  34. if(disponibil)
  35. {
  36. st[k] = i;
  37. Back(k+1);
  38. }
  39. }
  40. }
  41.  
  42. int main()
  43. {
  44. #ifndef ONLINE_JUDGE
  45. freopen ("date.in","r",stdin);
  46. freopen ("date.out","w",stdout);
  47. #endif
  48. n=1;
  49. Back(1);
  50.  
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement