TCS
Company
Category
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
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
Read Solution (Total 9)
-
- import java.util.*;
class MB{
public static void main(String arg[]){
int mod1,mod2,mod3,mod4,count1=0,count2=0,count3=0,count4=0,count5=0;
System.out.println("Milk in litres");
Scanner scan=new Scanner(System.in);
int litres=scan.nextInt();
do
{
mod1 =litres%10;
litres=litres-mod1;
litres=litres/10;
count1=count1+litres;
}while(litres>=10);
do
{
mod2 =mod1%7;
mod1=mod1-mod2;
mod1=mod1/7;
count2=count2+mod1;
}while(mod1>=7);
do
{
mod3 =mod2%5;
mod2=mod2-mod3;
mod2=mod2/5;
count3=count3+mod2;
}while(mod2>=5);
for(int i=0;i - 9 years agoHelpfull: Yes(3) No(1)
- #include
int process(int num)
{
int k1=0,k2=0,num2=num;
while(num>0)
{
if(num%10==0)
{
k1=k1+num/10;
num=num%10;
}
else if(num%7==0)
{
k1=k1+num/7;
num=num%7;
}
else if(num%5==0)
{
k1=k1+num/5;
num=num%5;
}
else
{
k1=k1+num;
num=0;
}
}
while(num2>0)
{
if(num2>=10)
num2=num2-10;
else if(num2>=7)
num2=num2-7;
else if(num2>=5)
num2=num2-5;
else
num2=num2-1;
k2++;
}
if(k1>k2)
return k2;
else
return k1;
}
void main()
{
int a[1000];
int n,i,num;
//printf("Enter Number of test cases:--");
scanf("%d",&n);
for(i=0;i - 9 years agoHelpfull: Yes(2) No(0)
#include
using namespace std;
int main()
{
int arr[]={1,5,7,10};
int N;
cin>>N;
while(N--)
{
long long L;
cin>>L;
long long ans=0,x;
ans=L/10;
if(ans)
L=L%10;
x=L/7;
if(x)
{
L=L%7;
ans+=x;
}
x=L/5;
if(x)
{
L=L%5;
ans+=x;
}
x=L;
if(x)
{
ans+=x;
}
cout- 8 years agoHelpfull: Yes(2) No(0)
- import java.util.*;
class MB{
public static void main(String arg[]){
int mod1,mod2,mod3,mod4,count1=0,count2=0,count3=0,count4=0,count5=0;
System.out.println("Milk in litres");
Scanner scan=new Scanner(System.in);
int litres=scan.nextInt();
do
{
mod1 =litres%10;
litres=litres-mod1;
litres=litres/10;
count1=count1+litres;
}while(litres>=10);
do
{
mod2 =mod1%7;
mod1=mod1-mod2;
mod1=mod1/7;
count2=count2+mod1;
}while(mod1>=7);
do
{
mod3 =mod2%5;
mod2=mod2-mod3;
mod2=mod2/5;
count3=count3+mod2;
}while(mod2>=5);
for(int i=0;i - 9 years agoHelpfull: Yes(1) No(3)
- #include
int process(int num)
{
int k1=0,k2=0,num2=num;
while(num>0)
{
if(num%10==0)
{
k1=k1+num/10;
num=num%10;
}
else if(num%7==0)
{
k1=k1+num/7;
num=num%7;
}
else if(num%5==0)
{
k1=k1+num/5;
num=num%5;
}
else
{
k1=k1+num;
num=0;
}
}
while(num2>0)
{
if(num2>=10)
num2=num2-10;
else if(num2>=7)
num2=num2-7;
else if(num2>=5)
num2=num2-5;
else
num2=num2-1;
k2++;
}
if(k1>k2)
return k2;
else
return k1;
}
void main()
{
int a[1000];
int n,i,num;
//printf("Enter Number of test cases:--");
scanf("%d",&n);
for(i=0;i - 9 years agoHelpfull: Yes(0) No(0)
- #include
int main(void) {
int i,j,N;
int Li[1000];
int count;
scanf("%d",&N);
if(N>0 && N=10)
{
count++;
Li[j]-=10;
goto here;
}
here1: if(Li[j]>=7)
{
count++;
Li[j]-=7;
goto here1;
}
here2: if(Li[j]>=5)
{
count++;
Li[j]-=5;
goto here2;
}
here3: if(Li[j]>=1)
{
count++;
Li[j]-=1;
goto here3;
}
printf("%d |n",count);
}
}
return 0;
}
} - 9 years agoHelpfull: Yes(0) No(1)
- import java.io.*;
public class Main {
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N;
N=Integer.parseInt(br.readLine());
int L[]=new int[N];
for(int i=0;i0){
L[i]=L[i]%10;
x=L[i]/7;
}
if(x>0){
L[i]=L[i]%7;
sum=sum+x;
}
x=L[i]/5;
if(x>0){
L[i]=L[i]%5;
sum=sum+x;
}
x=L[i];
if(x>0){
sum=sum+x;
}
}
System.out.println(sum);
}
}
}
- 8 years agoHelpfull: Yes(0) No(0)
- #include
#include
using namespace std;
int main()
{
int n,a[100],i,j,m,x,sum=0;
cin>>n>>m;
for(i=0;i>a[i];
}
for(i=0;i - 8 years agoHelpfull: Yes(0) No(0)
- #include
using namespace std;
int main()
{
int bottle,test,i,j;
int b[4]={1,5,7,10};
int sum=0;
int n[1000];
couttest;
for(i=0;i>n[i];
}
for(i=0;i=0)
{
while(sum>=b[j])
{
sum=sum-b[j];
bottle++;
}
j--;
}
cout - 6 years agoHelpfull: Yes(0) No(0)
TCS Other Question
A robot is programmed to move forward F meters and backwards again, say B meters, in a straight line. The Robot covers 1 meter in T units of time. On Robot's path there is a ditch at a distance FD from initial position in forward direction as well as a ditch at a distance BD from initial position in backward direction. This forward and backward movement is performed repeatedly by the Robot.
Your task is to calculate amount of time taken, before the Robot falls in either ditch, if at all it falls in a ditch.
Input Format:
First line contains total number of test cases, denoted by N
Next N lines, contain a tuple containing 5 values delimited by space
F B T FD BD, where
F denotes forward displacement in meters
B denotes backward displacement in meters
T denotes time taken to cover 1 meter
FD denotes distance from Robot's starting position and the ditch in forward direction
BD denotes distance from Robot's starting position and the ditch in backward direction
Output Format:
For each test case print time taken by the Robot to fall in the ditch and also state which ditch he falls into. Print F for forward and B for backward. Both the outputs must be delimited by whitespace
OR
Print No Ditch if the Robot does not fall in either ditch
Constraints:
First move will always be in forward direction
1 <= N <= 100
forward displacement > 0
backward displacement > 0
time > 0
distance of ditch in forward direction (FD) > 0
distance of ditch in backward direction (BD) > 0
All input values must be positive integers only
Sample Input and Output
SNo. Input Output
1
3
9 4 3 13 10
9 7 1 11 13
4 4 3 8 12
63 F
25 F
No Ditch
2
5
8 4 7 11 22
4 5 4 25 6
4 9 3 6 29
7 10 6 24 12
10 10 1 9 7
133 F
216 B
231 B
408 B
9 F
Between Devil and Deep Sea
A band of pirates have made loot. By their misfortune though, instant Karma is delivered. While they are travelling a treacherous route in the high and the deep seas they are also haunted by a devil, perhaps a spirit who suffered at their hands previously. The pirates now have to make tricky decisions. They run forward to save themselves from the Devil, but the deep seas force them backwards. There is a danger of falling in a whirlpool if they move forward rashly and there is a danger of being caught by the Devil if they move too much back. But move they must.
First they recede backwards B meters and then advance forward F meters, in a straight line. They cover 1 meter in T units of time. This backward and forward movement is performed repeatedly by the Pirates because they have panicked.
Your task is to find out if they will perish at the hands of the Devil or they will get sucked into the whirlpool of the Deep Sea and in how much time. It is also possible that by good fortune they might survive. Write a program to calculate the outcome