Output

advertisement
1. ATM
Pooja would like to withdraw X $US from an ATM. The cash machine will only accept the
transaction if X is a multiple of 5, and Pooja's account balance has enough cash to perform the
withdrawal transaction (including bank charges). For each successful withdrawal the bank
charges 0.50 $US.
Calculate Pooja's account balance after an attempted transaction.
Input
Positive integer 0 < X <= 2000 - the amount of cash which Pooja wishes to withdraw.
Nonnegative number 0<= Y <= 2000 with two digits of precision - Pooja's initial account balance.
Output
Output the account balance after the attempted transaction, given as a number with two digits
of precision. If there is not enough money in the account to complete the transaction, output
the current bank balance.
Example - Successful Transaction
Input:
30 120.00
Output:
89.50
Example - Incorrect Withdrawal Amount (not multiple of 5)
Input:
42 120.00
Output:
120.00
Example - Insufficient Funds
Input:
300 120.00
Output:
120.00
2. Life, the Universe, and Everything
Your program is to use the brute-force approach in order to find the Answer to Life, the
Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop
processing input after reading in the number 42. All numbers at input are integers of one or two
digits.
Example
Input:
1
2
88
42
99
Output:
1
2
88
3. Enormous Input Test
The purpose of this problem is to verify whether the method you are using to read input data is
sufficiently fast to handle problems branded with the enormous Input/ Output warning. You are
expected to be able to process at least 2.5MB of input data per second at runtime.
Input
The input begins with two positive integers n k (n, k<=107). The next n lines of input contain one
positive integer ti, not greater than 109, each.
Output
Write a single integer to output, denoting how many integers ti are divisible by k.
Example
Input:
73
1
51
966369
7
9
999996
11
Output:
4
4. Transform the Expression
Reverse Polish Notation (RPN) is a mathematical notation where every operator follows all of its
operands. For instance, to add three and four, one would write "3 4 +" rather than "3 + 4". If
there are multiple operations, the operator is given immediately after its second operand; so
the expression written "3 − 4 + 5" would be written "3 4 − 5 +" first subtract 4 from 3, then add 5
to that.
Transform the algebraic expression with brackets into RPN form.
You can assume that for the test cases below only single letters will be used, brackets [] will not
be used and each expression has only one RPN form (no expressions like a*b*c)
Input
The first line contains t, the number of test cases (less then 100).
Followed by t lines, containing an expression to be translated to RPN form, where the length of
the expression is less than 400.
Output
The expressions in RPN form, one per line.
Example
Input:
3
(a+(b*c))
((a+b)*(z+x))
((a+t)*((b+(a+c))^(c+d)))
Output:
abc*+
ab+zx+*
at+bac++cd+^*
5. Small factorials
You are asked to calculate factorials of some small positive integers.
Input
An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing
a single integer n, 1<=n<=100.
Output
For each integer n given at input, display a line with the value of n!
Example
Sample input:
4
1
2
5
3
Sample output:
1
2
120
6
6. Turbo Sort
Given the list of numbers, you are to sort them in non decreasing order.
Input
t – the number of numbers in list, then t lines follow [t <= 10^6].
Each line contains one integer: N [0 <= N <= 10^6]
Output
Output given numbers in non decreasing order.
Example
Input:
5
5
3
6
7
1
Output:
1
3
5
6
7
7. A Very Easy Problem!
Input
There's no input.
Output
Output some form of these numbers: 137, 1315, 73, 136, 255, 1384, 16385, one per line in the
listed order.
Example
Output:
The first two lines of the CORRECT output file are:
137=2(2(2)+2+2(0))+2(2+2(0))+2(0)
1315=2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2(0))+2+2(0)
The correct output file should contain 7 lines.
8. GCD2
Frank explained its friend Felman the algorithm of Euclides to calculate the GCD of two
numbers. Then Felman implements it algorithm
int gcd(int a, int b)
{
if (b==0)
return a;
else
return gcd(b,a%b);
}
and it proposes to Frank that makes it but with a little integer and another integer that has up to
250 digits.
Your task is to help Frank programming an efficient code for the challenge of Felman.
Input
The first line of the input file contains a number representing the number of lines to follow. Each
line consists of two number A and B (0 <= A <= 40000 and A <= B < 10^250).
Output
Print for each pair (A,B) in the input one integer representing the GCD of A and B.
Example
Input:
2
26
10 11
Output:
2
1
9. Primality Testing
Modern cryptosystems rely heavily on our inability to factor large integers quickly as the basis
for their security. They need a quick and easy way to generate and test for primes. Very often,
the primes generated are very large numbers. You need to implement ways to test the primality
of very large numbers.
Input
Line 1: A number (no more than 1000 digits long)
Output
Line 1: PRIME or COMPOSITE
Example
Input:
2760727302517
Output:
PRIME
10.
Parenthesis
The captain of TITANIC is a mathematics freak. He has recently been given a problem that he is
unable to solve. And he has asked your help to solve it.
There are n numbers in a given expression.
X1 X2 X3 .... Xn
What is the number of ways to put parenthesis in the expression.
For n=4, the different ways are
(((x1.x2).x3).x4)
((x1.x2).(x3.x4))
(x1.((x2.x3).x4))
(x1.(x2.(x3.x4)))
((x1.(x2.x3)).x4)
Hence the required answer would be 5.
Input
The first line contains the number of test cases t <=10. Each of the next t lines contain single
integers <=1000 denoting n.
Output
Display t lines containg the number of ways to put parenthesis in the expression of length n
modulo 10000.
Example
Input:
2
4
5
Output:
5
14
11.
Cigar Party
When squirrels get together for a party, they like to have cigars. A squirrel party is successful
when the number of cigars is between 40 and 60, inclusive. Unless it is the weekend, in which
case there is no upper bound on the number of cigars. Return true if the party with the given
values is successful, or false otherwise.
cigarParty(30, false) → false
cigarParty(50, false) → true
cigarParty(70, true) → true
Signature:
public boolean cigarParty(int cigars, boolean isWeekend) { }
12.
Squirrel Play
The squirrels in Palo Alto spend most of the day playing. In particular, they play if the
temperature is between 60 and 90 (inclusive). Unless it is summer, then the upper limit is 100
instead of 90. Given an int temperature and a boolean isSummer, return true if the squirrels
play and false otherwise.
squirrelPlay(70, false) → true
squirrelPlay(95, false) → false
squirrelPlay(95, true) → true
Signature:
public boolean squirrelPlay(int temp, boolean isSummer) {
}
13.
Caught Speeding
You are driving a little too fast, and a police officer stops you. Write code to compute the result,
encoded as an int value: 0=no ticket, 1=small ticket, 2=big ticket. If speed is 60 or less, the result
is 0. If speed is between 61 and 80 inclusive, the result is 1. If speed is 81 or more, the result is 2.
Unless it is your birthday -- on that day, your speed can be 5 higher in all cases.
caughtSpeeding(60, false) → 0
caughtSpeeding(65, false) → 1
caughtSpeeding(65, true) → 0
Signature:
public int caughtSpeeding(int speed, boolean isBirthday) {}
14.
Sorta Sum
Given 2 ints, a and b, return their sum. However, sums in the range 10..19 inclusive, are
forbidden, so in that case just return 20.
sortaSum(3, 4) → 7
sortaSum(9, 4) → 20
sortaSum(10, 11) → 21
Signature:
public int sortaSum(int a, int b) {}
15.
Alarm Clock
Given a day of the week encoded as 0=Sun, 1=Mon, 2=Tue, ...6=Sat, and a boolean indicating if
we are on vacation, return a string of the form "7:00" indicating when the alarm clock should
ring. Weekdays, the alarm should be "7:00" and on the weekend it should be "10:00". Unless we
are on vacation -- then on weekdays it should be "10:00" and weekends it should be "off".
alarmClock(1, false) → "7:00"
alarmClock(5, false) → "7:00"
alarmClock(0, false) → "10:00"
Signature:
public String alarmClock(int day, boolean vacation) {}
16.
Lone Sum
Given 3 int values, a b c, return their sum. However, if one of the values is the same as another
of the values, it does not count towards the sum.
loneSum(1, 2, 3) → 6
loneSum(3, 2, 3) → 2
loneSum(3, 3, 3) → 0
Signature:
public int loneSum(int a, int b, int c) {}
Download