# Best answer of tcs codevita 2015 questions

Friends, you may have faced C++ questions in Codevita exam organized by TCS. Here is an answer to a question asked in TCS codevita. If you need more questions go to TCS codevita important questions 2015.

## TCS codevita Question

### Problem : Milk Man and His Bottles

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 21765 27

Explanation:

Number of test cases is 2

In first test case, demand of milk is 17 litres which can be supplied using minimum of 2 bottles as follows
1 x 10 litres and
1 x 7 litres
In second test case, demand of milk is 65 litres which can be supplied using minimum of 7 bottles as follows
6 x 10 litres and
1 x 5 litres

Solution : Milk Man and His Bottles

#include <iostream>
using namespace std;
int minimum(int n1,int n2,int n3)
{
int a[3]={n1,n2,n3},minim=a[0];
for(int i=0;i<3;i++)
{
if(minim>a[i])
minim=a[i];
}
return minim;
}
int f(int n,int no)
{
if(n==1||n==5||n==7||n==10)
return no+1;
if(n>1&&n<5)
return (f(n-1,no+1));
if(n>5&&n<7)
return (f(n-5,no+1));
if(n>7&&n<10)
return (f(n-7,no+1));
if(n>10)
{
return(minimum(f(n-7,no+1),f(n-10,no+1),f(n-5,no+1)));
}
cout<<“error”;
return 0;
}
int main()
{int n,cases;
cout<<“Enter cases: “;
cin>>cases;
for(int i=0; i<cases; i++){
cout<<“Enter demand: “;
cin>>n;
cout<<“minimum no of bottles required are: “;
cout<<f(n,0)<<“n”;
}
return 0;
}

Mr. Sai kalyan gave me the code for this milkman question in java. Here it is

/* package codechef; // don’t place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be “Main” only if the class is public. */
class Milkman
{
public static void main (String[] args) throws java.lang.Exception
{
int[] bottles = {10,7,5,1};
int[] result = new int[test_case];
int milk,lts,btl,j;
for(int i=0; i<test_case;i++)
{
j=0;
btl=0;
while(milk>0)
{
lts   = milk/bottles[j];
milk -= bottles[j]*lts;
j++;
btl += lts;
}
result[i] = btl;
}
for(int i=0;i<test_case;i++)
System.out.println(result[i]);
}
}

The Codevita problem code is well understood if you have any problem in any of the codes give your suggestion in the comment section. I will be Happy to Help you.

Help others by Sharing this post. Thank you.

## What are the benefits of investing in logistics application development

Gears surrounding the fulcrum act as a force multiplier. Logistics software solutions are the same for the economy of any country. Just about \$10 trillion is a mammoth market for…

## What Are the Key Steps to Develop a Blockchain App?

By offering distributed, safe, open platforms, blockchain technology has transformed sectors. To guarantee that a blockchain app satisfies the intended functionality and security criteria, development of one calls for meticulous…

## The Role of Full Stack Developers in Modern Web Development

Web development is highly lucrative due to its increased demand. The need for a full stack web developer is growing. Thus, this makes it a sought-after skill. The demand for…

## Role of AI in Accelerating Software Development Processes

Artificial Intelligence has gained huge traction in the last few years. However, the growth has significantly risen due to recent technological advancements. AI’s allied disciplines along with machine learning and…

## Step-by-Step Guide: How to Convert EML Files to HTML

In most cases, EML files are used in various email programs for storing single emails or electronic mail. Though most of the email clients support EML format, you canâ€™t (without…

## Game-Changing Benefits of PWA Development for eCommerce Success

The e-commerce industry has been highly competitive since it was launched. The online shopping trend will stay and there will be no decline.  As per recent statistics, the eCommerce market…