02 Data Types and Variables Exercise
02 Data Types and Variables Exercise
Please, submit your source code solutions for the described problems to the Judge System.
1. Integer Operations
Write a program that reads four integer numbers. It should add the first to the second number, integer divide the
sum by the third number, and multiply the result by the fourth number. Print the final result.
Examples
Input Output Input Output
10 30 15 42
20 14
3 2
3 3
2. Chars to String
Write a function that receives 3 characters. Concatenate all the characters into one string and print it on the
console.
Examples
Input Output
a abc
b
c
% %2o
2
o
1 15p
5
p
3. Elevator
Calculate how many courses will be needed to elevate N persons by using an elevator with a capacity of P persons.
The input holds two lines: the number of people N and the capacity P of the elevator.
Examples
Input Output Comments
17 6 5 courses * 3 people
3 + 1 course * 2 persons
4 1 All the people fit inside the elevator.
5 Only one course is needed.
10 2 2 courses * 5 people
5
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
4. Sum of Chars
Write a program, which sums the ASCII codes of N characters and prints the sum on the console. On the first line,
you will receive N – the number of lines. On the following N lines – you will receive a letter per line. Print the total
sum in the following format: "The sum equals: {total_sum}".
Note: n will be in the interval [1…20].
Examples
Input Output Input Output
5 The sum equals: 399 12 The sum equals: 1263
A S
b o
C f
d t
E U
n
i
R
u
l
z
z
Examples
Input Output
60 < = > ? @ A
65
69 E F G H I J K L M N O
79
97 a b c d e f g h
104
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Examples
Input Output Input Output
3 aaa 2 aaa
aab aab
aac aba
aba abb
abb baa
abc bab
aca bba
acb bbb
acc
baa
bab
bac
bba
bbb
bbc
bca
bcb
bcc
caa
cab
cac
cba
cbb
cbc
cca
ccb
ccc
Hints
Perform 3 nested loops from 0 to N:
7. Water Overflow
You have a water tank with a capacity of 255 liters. On the first line, you will receive n – the number of lines, which
will follow. On the following n lines, you will receive liters of water (integers), which you should pour into your tank.
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Examples
Input Output Input Output
5 Insufficient capacity! 1 Insufficient capacity!
20 240 1000 0
100
100
100
20
7 105 4 Insufficient capacity!
10 250 Insufficient capacity!
20 10 Insufficient capacity!
30 20 250
10 40
5
10
20
8. * Party Profit
As a young adventurer, you travel with your group worldwide, seeking for gold and glory. But you need to split the
profit among your companions.
You will receive a group size. After that, you receive the days of the adventure.
Every day, you earn 50 coins, but you also spend 2 coins per companion for food.
Every 3rd (third) day, you organize a motivational party, spending 3 coins per companion for drinking water.
Every 5th (fifth) day, you slay a boss monster and gain 20 coins per companion. But if you have a motivational party
the same day, you spend an additional 2 coins per companion.
Every 10th (tenth) day at the start of the day, 2 (two) of your companions leave, but every 15th (fifteenth) day 5
(five) new companions are joined at the beginning of the day.
You should calculate how many coins gets each companion at the end of the adventure.
Input / Constraints
The input will consist of exactly 2 lines:
group size – integer in the range [1…100]
days – integer in the range [1…100]
Output
Print the following message: "{companions_count} companions received {coins} coins each."
Note: You cannot split a coin, so you should round down the coins to an integer number.
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
9. *Snowballs
Tony and Andi love playing in the snow and having snowball fights, but they always argue about who makes the best
snowballs. They have decided to involve you in their fray by writing a program that calculates snowball data and
outputs the best snowball value.
You will receive N – an integer, the number of snowballs being made by Tony and Andi.
On the following lines, you will receive 3 inputs for each snowball:
The weight of the snowball (integer).
The time needed for the snowball to get to its target (integer).
The quality of the snowball (integer).
For each snowball, you must calculate its value by the following formula:
(snowball_weight / snowball_time) ** snowball_quality
In the end, you must print the highest calculated value of a snowball.
Input
On the first input line, you will receive N – the number of snowballs.
On the next N*3 input lines, you will be receiving data about each snowball.
Output
You need to print the highest calculated snowball's value in the format:
"{snowball_weight} : {snowball_time} = {snowball_value} ({snowball_quality})"
Constraints
The number of snowballs (N) will be an integer in the range [0, 100].
The weight is an integer in the range [0, 1000].
The time is an integer in the range [1, 500].
The quality is an integer in the range [0, 100].
Examples
Input Output
2 10 : 2 = 125 (3)
10
2
3
5
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Input / Constraints
The input will consist of 5 lines:
On the first line, you will receive the lost fights count – an integer in the range [0, 1000].
On the second line, you will receive the helmet price - a floating-point number in the range [0, 1000].
On the third line, you will receive the sword price - a floating-point number in the range [0, 1000].
On the fourth line, you will receive the shield price - a floating-point number in the range [0, 1000].
On the fifth line, you will receive the armor price - a floating-point number in the range [0, 1000].
Output
As output, you must print Peter`s total expenses for new equipment: "Gladiator expenses:
{expenses} aureus"
Examples
Input Output Comment
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.