Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream cin ("permutari1.in");
  4. ofstream cout ("permutari1.out");
  5. int st[20],n;
  6. void succesor (int k, int &as)
  7. {
  8. if (st[k]>1)
  9. {
  10. as=1;
  11. st[k]--;
  12. }
  13. else as=0;
  14. }
  15. void valid (int k, int &ev)
  16. {
  17. ev=1;
  18. for (int i=1; i<k; i++)
  19. if (st[i]==st[k])
  20. ev=0;
  21. }
  22. int solutie (int k)
  23. {
  24. if (k==n)
  25. return 1;
  26. else return 0;
  27. }
  28. int tipar ()
  29. {
  30. for (int i=1; i<=n; i++)
  31. cout<<st[i]<<" ";
  32. cout<<endl;
  33. }
  34. int main()
  35. {
  36. int as,ev,k;
  37. cin>>n;
  38. k=1;
  39. st[k]=n+1;
  40. while (k>0)
  41. {
  42. do
  43. {
  44. succesor (k,as);
  45. if (as==1)
  46. valid (k, ev);
  47. }
  48. while (as==1 && ev==0);
  49. if (as==1)
  50. if (solutie (k)==1)
  51. tipar ();
  52. else
  53. {
  54. k++;
  55. st[k]=n+1;
  56. }
  57. else k--;
  58. }
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement