Advertisement
Guest User

frf

a guest
Feb 26th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int P[100];
  7. int N,K,S;
  8. int A[100][50];
  9.  
  10. void Olvas()
  11. {
  12. ifstream f("penz.txt");
  13. f>>N>>K;
  14. for(int i=1;i<=N;i++)
  15. {
  16. f>>P[i];
  17. S+=P[i];
  18. }
  19. f.close();
  20.  
  21. }
  22.  
  23. int Kiir(int x[])
  24. {
  25. for(int i=1;i<=N;i++)
  26. {
  27. cout.width(4);
  28. cout<<x[i]<<" ";
  29. }
  30. cout <<endl;
  31. cout<<"Kifizetendo: "<<K;
  32. cout <<endl;
  33. }
  34.  
  35. int Fizetheto()
  36. {
  37. return 1;
  38. }
  39.  
  40. void fizet()
  41. {
  42. for(int i=0;i<=N;i++)
  43. {
  44. for(int j=1;j<=12;j++)
  45. {
  46. if(Fizetheto())
  47. A[i][j]=1;
  48. }
  49. }
  50. }
  51.  
  52. void Mutat()
  53. {
  54. for(int i=0;i<=N;i++)
  55. {
  56. for(int j=1;j<=12;j++)
  57. {
  58. cout<<A[i][j];
  59. }
  60. }
  61. }
  62.  
  63. void Feltolt()
  64. {
  65. A[P[1]][1]=1;
  66. for(int i=2;i<=N;i++)
  67. {
  68. for(int x=1;x<=K;x++)
  69. {
  70. if(A[x][i-1]==1)
  71. A[x][i]=1;
  72. else
  73. if(x==P[i])
  74. A[x][i]=1;
  75. else
  76. if(x>P[i] && A[x-P[i]][i-1]==1)
  77. A[x][i]=1;
  78. }
  79. }
  80. }
  81.  
  82. void Nyomtat()
  83. {
  84. for(int i=1;i<=K;i++)
  85. {
  86. cout.width(4);
  87. cout<<i<<" lej:";
  88. for(int j=1;j<=N;j++)
  89. {
  90. cout.width(4);
  91. cout<<A[i][j];
  92. }
  93. cout<<endl;
  94. }
  95. cout<<endl;
  96. }
  97.  
  98. void Eredmeny()
  99. {
  100. if(A[K][N]==0)
  101. cout<<"nem kifizetheto az osszeg!!";
  102. else
  103. {
  104. int x=K, i=N;
  105. while(A[x][i]>0)
  106. {
  107. while(i>=1 && A[x][i]==A[x][i-1])
  108. i--;
  109. cout<<P[i]<<" ";
  110. x=x-P[i];
  111. i--;
  112.  
  113. }
  114. }
  115. }
  116.  
  117. int main()
  118. {
  119. Olvas();
  120. Kiir(P);
  121. if(K>S)
  122. {
  123. cout<<"Nem fizetheto ki az oszzeg!";
  124. return 0;
  125. }
  126. Feltolt();
  127. Nyomtat();
  128. Eredmeny();
  129.  
  130. return 0;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement