Answer to Question #54004 in C++ for santhosh

Question #54004
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.
1
Expert's answer
2015-10-07T04:10:29-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 first!

Leave a comment

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS
paypal