public int makeChocolate(int small, int big, int goal) {
int i,j;
for(i=0;(goal>0&&i<big);i++)
goal-=5;
if(goal==0) return 0;
else if(goal<0) goal+=5;
for(j=0;(j<small&&goal>0);j++) goal-=1;
if(goal==0) return j;
else return -1;
}
int i,j;
for(i=0;(goal>0&&i<big);i++)
goal-=5;
if(goal==0) return 0;
else if(goal<0) goal+=5;
for(j=0;(j<small&&goal>0);j++) goal-=1;
if(goal==0) return j;
else return -1;
}
Comments
Post a Comment