Professional Documents
Culture Documents
Problem : Catch-22 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
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
whitespaceOR 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 >
0backward 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
Question 2
Problem : Saving for a rainy day By nature, an average Indian believes in saving money. Some
reports suggest that an average Indian manages to save approximately 30+% of his salary.
Dhaniram is one such hard working fellow. With a view of future expenses, Dhaniram resolves to
save a certain amount in order to meet his cash flow demands in the future. Consider the
following example. Dhaniram wants to buy a TV. He needs to pay Rs 2000/- per month for 12
installments to own the TV. If let's say he gets 4% interest per annum on his savings bank
account, then Dhaniram will need to deposit a certain amount in the bank today, such that he is
able to withdraw Rs 2000/- per month for the next 12 months without requiring any additional
deposits throughout. Your task is to find out how much Dhaniram should deposit today so that he
gets assured cash flows for a fixed period in the future, given the rate of interest at which his
money will grow during this period.
Input Format: First line contains desired cash flow M Second line contains period in months
denoted by TThird line contains rate per annum R expressed in percentage at which deposited
amount will grow
Output Format: Print total amount of money to be deposited now rounded off to the nearest
integerConstraints: M > 0 T > 0 R >= 0 Calculation should be done upto 11-digit precision
Sample Input and Output
SNo. Input Output
1 500 3 12 1470
3 500 2 0 1000
Question 3
Problem : Sheldon Cooper and his beverage paradigm Sheldon Cooper, Leonard
Hofstadter and Penny decide to go for drinks at Cheese cake factory. Sheldon proposes
to make a game out of this. Sheldon proposes as follows,
Constraints: N >= 3 Ai > 0 1 <= i <= N X > 0 Sample Input and Output
SNo. Input Output
1 6 1 4 45 6 10 8 22 True
2 4 1 3 12 4 14 False
Explanation for sample input and output 1: The sum of 2nd, 5th and 6th beverage
size is equal to 22. So the output will be True.
Explanation for sample input and output 2: Since no combination of given beverage
sizes sum up to X i.e. 14, the output will be False.
Question 4
Problem : Water Management There are N tubs of water, numbered from 1 to N.
Initially there is a few litres of water in each tub. Each water tub has 2 taps attached to
it. Incoming Tap with speed x litres / second and Outgoing Tap with speed y litres /
second. Let water(i) denote the final volume of water in ith tub. Amit wants to attain such
a situation that water(i) < water(i+1) for 1<=i <=N. i.e. water in each tub must be less
than water in the tub next to it. He wants to do this as quickly as possible. You task is to
find out and tell Amit, what is the minimum number of seconds required to attain in this
situation.
Input Format: First line will contains the number of tubs, denoted by N Next N lines
contain a tuple with 3 integers delimited by white space. The tuple contents are
Explanation for sample input and output 1: Here we have 3 tubs with following
information about each of them
Tub Number Initial Volume Incoming Tap speed Outgoing Tap speed
Tub 1 2 3 3
Tub 2 3 4 5
Tub 3 3 5 5
Initially tub 2 and 3 have same volume of water. So he will just turn on the Incoming Tap
at Tub 3 for one second. After one second the water in 3rd tub will be 8 litres. Since 2 <
3 < 8, the answer is 1 second.
Explanation for sample input and output 2: Here we have 3 tubs with following
information about each of them
Tub Number Initial Volume Incoming Tap speed Outgoing Tap speed
Tub 1 6 2 1
Tub 2 4 1 3
Tub 3 4 1 4
As we can see that it is impossible to do the task in one second. But it can be done in
two second as below. Turn on the outgoing tap at tub 1. So after two seconds water
level will reduce to 4 litres. Turn on the incoming tap at tub 2 only for one second. So
water level will be 5 litres. Turn on the incoming tap at tub 3 for two seconds. So water
level will be 6 litres. Since 4 < 5 < 6, the answer is 2 seconds.
Question 5
Question 6
Problem : Hotel trip Tom, Dick and Harry go to a restaurant. Each of them has a certain
amount of money. When their monies are pooled they discover they have S Rs. Next,
they start going through the menu card to choose items they would like to order. Your
task is to help them find out how many different menu item combinations they can order.
Since there can be many menu items with the same price, we are interested only in
unique price combinations. Refer output specifications and examples to get a better
understanding.
Input Format: First line contains N positive integers delimited by space, corresponding
to prices of N menu items Second line contains an integer S corresponding to the
amount of money pooled between them
Output Format:
1. Print all possible combinations of item prices whose sum is equal to S. Enclose each such
combination in square brackets [ ]. Elements should be separated by, followed by a space
character.
2. Item price combinations must be unique (See example 2 to understand this better)
3. If more than one combinations exists, then the print order should be as follows
1. Combinations should be printed in descending order item prices
2. Two combinations can be differentiated by first comparing their costliest,
followed by second costliest, and followed by the next costliest item, so on and so forth. Refer
example outputs for better understanding of print order.
Constraints: Pi > 0 ; where i = 1 to N and Pi denotes the price of the ith item S > 0 Sample
Input and Output
Input Format:
First 5 lines of the input provides security name and its prices for the whole month
Columns in these lines are space delimited. First column provides security name and next
22 columns has price for 22 working days of the month
Sixth line onwards is your trade data in ascending order of trade dates
Trade data comprises of 4 values viz. <date, Buy(B)/ Sell(S), Security name, quantity>
Trade data is terminated by a line comprising -1
Refer example section on how to read input
Output Format:
1. Print security name and holdings for all securities where holding is non-zero, delimited
by space. Print order for securities where holdings are non-zero is governed by the rule -
1. Securities and their holdings should be printed in the order in which their prices
are provided in input.
2. See Explanation section below for better understanding.
2. Print Profit or Loss incurred due to trades in the format "Profit = <Value>" or "Loss =
<Value>"
Constraints: Date will be always be between 1 and 30 (both inclusive) Sample Input and
Output
SNo. Input Output
1 tcs 220 250 260 230 200 210 250 260 230 200 260 230 200 220 250 270 tcs 200 xyz
260 230 200 260 230 200 inf 220 250 260 230 200 260 230 200 220 270 40 pqr 70
250 260 230 200 220 250 270 260 230 260 230 200 cts 260 230 200 220 Loss =
250 270 260 230 200 220 270 250 260 230 260 230 220 250 260 230 200 1700
260 xyz 220 250 260 230 200 260 230 200 220 250 270 260 230 200 220
250 250 260 230 260 230 220 pqr 220 250 270 260 230 200 220 270 250
260 230 260 230 220 250 200 220 250 250 260 230 260 1 B tcs 100 3 B tcs
150 5 B xyz 40 8 S tcs 50 9 B pqr 70 -1
2 tcs 220 250 260 230 200 510 250 260 230 200 260 230 200 220 250 270 tcs 50 xyz
260 230 200 260 230 200 inf 220 250 260 230 200 260 230 200 220 270 40 pqr 70
250 260 230 200 220 250 270 260 230 260 230 200 cts 260 230 200 220 Profit =
250 270 260 230 200 220 270 250 260 230 260 230 220 250 260 230 200 14500
260 xyz 220 250 260 230 200 260 230 200 220 250 270 260 230 200 220
250 250 260 230 260 230 220 pqr 220 250 270 260 230 200 220 270 250
260 230 260 230 220 250 200 220 250 250 260 230 260 1 B tcs 100 5 B xyz
40 8 S tcs 50 9 B pqr 70 -1
3 tcs 300 290 350 300 300 390 250 250 230 200 260 230 200 320 250 270 Loss =
260 230 200 260 230 200 wip 350 250 260 330 370 270 280 300 230 390 5000
350 360 230 350 220 250 270 260 230 260 230 200 Per 370 330 280 370
250 370 360 330 280 220 270 350 260 260 260 330 290 250 260 330 230
260 syn 240 290 380 240 230 260 300 250 250 250 270 260 230 200 220
250 250 260 230 260 230 220 sie 250 350 270 260 240 260 220 270 250
260 230 260 230 240 250 280 240 250 250 260 230 260 3 B tcs 100 4 S tcs
70 5 S tcs 30 -1
import java.util.*;
class Milk
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n,t,h=0,s;
s=sc.nextInt();
if(s<1||s>1000){System.exit(0);}
int a[]=new int[s];
for(int i=0;i<s;i++)
{
n=sc.nextInt();
if(n<0){System.exit(0);}
if(n<10)
{
h=0;
t=n;
}
else
{
h=n/10;
t=n%10;
}
if(t==1||t==5||t==7)
a[i]=h+1;
else if(t==2||t==6||t==8)
a[i]=h+2;
else if(t==3||t==9)
a[i]=h+3;
else if(t==4)
a[i]=h+4;
else
a[i]=h;
}
for(int i=0;i<s;i++)
System.out.println(a[i]);
}
}
Input Format:
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
17
65 2
7
Explanation:
1. 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
2. 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>
int main(){
int N,Demand,code,left,L;
for(int i=0;i<N;i++)
cin>>Demand;
code= Demand/10;
L=code;
code*=10;
Demand-=code;
switch (Demand){
case 1: left=1;
break;
case 2: left=2;
break;
case 3: left=3;
break;
case 4: left=4;
break;
case 5: left=1;
break;
case 6: left=2;
break;
case 7: left=1;
break;
case 8: left=2;
break;
case 9: left=3;
break;
L+=left;
return 0;