Answer to Question #54008 in C++ for srimathi

Question #54008
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 Li which 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 1
2 17 65

2 7
1
Expert's answer
2015-08-10T02:28:02-0400
Solve

#include <stdio.h>
#include <fstream>

int main()
{
std::ifstream f("input.txt");
std::ofstream f_res("output.txt");
if(!f.is_open())
return -1;
else
{
int N,L;
f>>N;
for(int i=0;i<N;i++)
{
f>>L;
int numberBottles=L/10;
L=L%10;
numberBottles+=L/7;
L=L%7;
numberBottles+=L/5;
L=L%5;
numberBottles+=L;
f_res<<numberBottles<<std::endl;
}
f.close();
f_res.close();
}
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS