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
2016-07-19T08:36:02-0400
import java.util.Scanner;
public class Main {
public static void main(String[] args) { Scanner sc = new Scanner(System.in);
int N = sc.nextInt(); int[] bottles = new int[N]; for (int i = 0; i < N; i++) { int milk = sc.nextInt(); bottles[i] = 0;
bottles[i] += milk / 10; milk %= 10;
bottles[i] += milk / 7; milk %= 7;
bottles[i] += milk / 5; milk %= 5;
bottles[i] += milk; }
for (int i = 0; i < N; i++) System.out.print(bottles[i] + " "); } }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
thank you for your answer .
Leave a comment