Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main() {
- int a[5];
- int i,n;
- int vkupnotermini=0;
- int nevaliden=0;
- int termini[5];
- int prosekslobodni=0;
- for(i=0; i<5; i++) {
- scanf("%d",&a[i]);
- vkupnotermini+=a[i];
- if(a[i]<0)
- nevaliden=1;
- }
- scanf("%d",&n);
- if(nevaliden==0) {
- if(n>vkupnotermini)
- nevaliden=2;
- }
- prosekslobodni=vkupnotermini/5;
- while(n>0) {
- for(i=0; i<5; i++) {
- if(n<=0) {
- termini[i]=0;
- } else if(a[i]>=prosekslobodni) {
- if(n<a[i]) {
- termini[i]=n;
- n-=n;
- } else {
- termini[i]=prosekslobodni;
- n-=prosekslobodni;
- }
- } else if(a[i]<=prosekslobodni) {
- termini[i]=a[i];
- n-=a[i];
- }
- }
- if(n>0) {
- for(i=0; i<5; i++) {
- if(termini[i]<a[i]) {
- n-=a[i]-termini[i];
- termini[i]=a[i];
- }
- }
- }
- }
- if(nevaliden==1)
- printf("NEVALIDEN VLEZ");
- else if(nevaliden==2)
- printf("NEMA DOVOLNO SLOBODNI TERMINI");
- else {
- printf("RASPORED NA TERMINI\n");
- for(i=0; i<5; i++) {
- if(i==0)
- printf("Ponedelnik: %d\n",termini[i]);
- else if(i==1)
- printf("Vtornik: %d\n",termini[i]);
- else if(i==2)
- printf("Sreda: %d\n",termini[i]);
- else if(i==3)
- printf("Chetvrtok: %d\n",termini[i]);
- else if(i==4)
- printf("Petok: %d\n",termini[i]);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement