Milk Man and His Bottles- Code Vita 2015 | round 1

               Milk Man and His Bottles

Problem

A Milkman serves milk in packaged bottles of varied sizes. The possible size of the bottles are {1, 5, 7 and 10} litres. He wants to supply desired quantity using as less bottles as possible irrespective of the size. Your objective is to help him find the minimum number of bottles required to supply the given demand of milk.

Input Format: 

First line contains number of test cases N Next N lines, each contain a positive integer Liwhich corresponds to the demand of milk. 

Output Format:

 For each input Li, print the minimum number of bottles required to fulfill the demand 

Constraints: 

1 <= N <= 1000 Li > 0 1 <= i <= N 

Sample Input and Output

SNo.
Input
Output
12
17
 65
2
7
  
Explanation:
Number of test cases is 2
For 17 = 10*1 + 7*1 = 2
For 65 = 10*6 + 5*1 = 7

Few more examples:
For 99 = 10*9 + 7*1 + 1*2 = 12
For 63 = 10*6 + 1*3 =9

Program:

#include <stdio.h>
int main()
{
int n,b=0,i,m,s=0;
scanf("%d",&m);
for( i=0;i<m;i++)
{
scanf("%d",&n);
b=n/10;
n=n%10;
s=s+b;
b=0;
b=n/7;
n=n%7;
s=s+b;
b=0;
b=n/5;
n=n%5;
s=s+b;
b=0;
b=n/1;
s=s+b;
printf("%d\n",s);
s=0;
b=0;
}
return 0;
}

Output:

2
17
65

2
7

You can also run it on a online 

Your feedback are always welcome! If you have any doubt you can contact me or leave a comment!! Cheers!!!


Related Links:Minimum product array

1 comment:

  1. This doesn't work for corner cases,
    like for n=12, your code will give s=3(10*1 + 1*3),
    but the minimum no. of bottles can be obtained by
    s=2 (7*1 + 5*1). Similarly for numbers like 14...

    ReplyDelete

Super Market Problem | TCS Code Vita 2023 - Zone 1 | Super Market TCS Code Vita 2023 Solution | Code Vita 2023 | Code Vita 2023 season 11 solution

 Problem Description: In a Super market we will find many variations of the same product. In the same way we can find many types of rice bag...