Advertisement
damch

sh

Dec 3rd, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int a[5];
  5. int i,n;
  6. int vkupnotermini=0;
  7. int nevaliden=0;
  8. int termini[5];
  9. int prosekslobodni=0;
  10. for(i=0; i<5; i++) {
  11. scanf("%d",&a[i]);
  12. vkupnotermini+=a[i];
  13. if(a[i]<0)
  14. nevaliden=1;
  15. }
  16. scanf("%d",&n);
  17. if(nevaliden==0) {
  18. if(n>vkupnotermini)
  19. nevaliden=2;
  20. }
  21. prosekslobodni=vkupnotermini/5;
  22. while(n>0) {
  23. for(i=0; i<5; i++) {
  24. if(n<=0) {
  25. termini[i]=0;
  26. } else if(a[i]>=prosekslobodni) {
  27. if(n<a[i]) {
  28. termini[i]=n;
  29. n-=n;
  30. } else {
  31.  
  32. termini[i]=prosekslobodni;
  33. n-=prosekslobodni;
  34. }
  35.  
  36. } else if(a[i]<=prosekslobodni) {
  37. termini[i]=a[i];
  38. n-=a[i];
  39. }
  40. }
  41. if(n>0) {
  42. for(i=0; i<5; i++) {
  43. if(termini[i]<a[i]) {
  44. n-=a[i]-termini[i];
  45. termini[i]=a[i];
  46. }
  47. }
  48. }
  49. }
  50. if(nevaliden==1)
  51. printf("NEVALIDEN VLEZ");
  52. else if(nevaliden==2)
  53. printf("NEMA DOVOLNO SLOBODNI TERMINI");
  54. else {
  55. printf("RASPORED NA TERMINI\n");
  56. for(i=0; i<5; i++) {
  57. if(i==0)
  58. printf("Ponedelnik: %d\n",termini[i]);
  59. else if(i==1)
  60. printf("Vtornik: %d\n",termini[i]);
  61. else if(i==2)
  62. printf("Sreda: %d\n",termini[i]);
  63. else if(i==3)
  64. printf("Chetvrtok: %d\n",termini[i]);
  65. else if(i==4)
  66. printf("Petok: %d\n",termini[i]);
  67. }
  68. }
  69.  
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement