0% found this document useful (0 votes)
18 views6 pages

Clock - Problem Description

sdfasdf

Uploaded by

Marko Jovanovic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views6 pages

Clock - Problem Description

sdfasdf

Uploaded by

Marko Jovanovic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Lab: Nested Loops

Problems for lab exercise for the course "Programming Basics" course @ SoftUni Global
Submit your solutions to the SoftUni Judge system: https://judge.softuni.org/Contests/4587

1. Clock
Write a function that prints the hours of the day from 0:0 to 23:59, each on a separate line. The hours must be
printed in the format "{hours}:{minutes}".

Sample Input and Output


Input Output
(no input) 0:0
0:1
0:2
0:3
0:4
0:5
0:6
0:7
0:8
0:9
0:10
...
23:50
23:51
23:52
23:53
23:54
23:55
23:56
23:57
23:58
23:59

Hints and Guidelines


1. Create 2 nested for loops to iterate through every minute and hour of the day:

2. Print the result:

Testing in the Judge System


Test your solution in the online Judge system: https://judge.softuni.org/Contests/Compete/Index/4587#0

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 1 of 6


2. Multiplication Table
Print on the console the multiplication table for the numbers 1 to 10 in the format
"{first multiplier} * {second multiplier} = {result}".

Sample Input and Output


Input Output
(no input) 1 * 1 = 1
1 * 2 = 2
1 * 3 = 3
1 * 4 = 4
1 * 5 = 5
1 * 6 = 6
1 * 7 = 7
1 * 8 = 8
1 * 9 = 9
1 * 10 = 10
...
10 * 1 = 10
10 * 2 = 20
10 * 3 = 30
10 * 4 = 40
10 * 5 = 50
10 * 6 = 60
10 * 7 = 70
10 * 8 = 80
10 * 9 = 90
10 * 10 = 100

Hints and Guidelines


1. Create 2 nested for loops to iterate over each possible value of the two multipliers from 1 to 10:

2. Find the product of the two multipliers and print the result:

Testing in the Judge System


Test your solution in the online Judge system: https://judge.softuni.org/Contests/Compete/Index/4587#1

3. Combinations
Write a function that calculates how many solutions in natural numbers (including zero) have the equation:
x1 + x2 + x3 = n
The number n is an integer and is entered from the console.

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 2 of 6


Sample Input and Output
Input Output Comments Input Output Input Output
25 351 We generate all combinations of 3 numbers, the 20 231 5 21
first being:
0+0+0=0, but since it is not equal to 25, we
continue:
0+0+1=1 – also not 25, etc.
We come to the first valid combination:
0 + 0 + 25 = 25, we increase the number of valid
combinations by 1, the second valid combination
is:
0 + 1 + 24 = 25
The third:
0 + 2 + 23 = 25, etc.
After generating all possible combinations, the
number of valid ones is 351.

Hints and Guidelines


1. Read the input data - an integer n entered by the user, and store it in a variable;
2. Create 3 nested for loops to iterate every possible value of one of the 3 numbers in the equation:

3. Check the innermost nested loop for the values of x1, x2, and x3 in each iteration. For the equation to be
valid, its sum must be equal to n. Create a combinations_count variable to store the number of valid
combinations and add to it each time you generate one:

4. Finally, print the number of valid combinations.

Testing in the Judge System


Test your solution in the online Judge system: https://judge.softuni.org/Contests/Compete/Index/4587#2

4. Sum of Two Numbers


Write a function that checks all possible combinations of a pair of numbers in the interval of two given numbers.
The output prints which in order is the first combination whose sum of the numbers equals a given magic number.
If there is no combination matching the condition, a message is printed that none was found.

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 3 of 6


Input Data
The input is read from the console and consists of three lines:
 First line - beginning of the interval - an integer in the range [1...999]
 Second line - end of the interval - an integer in the range [greater than the first one...1000]
 Third line - a magic number - an integer in the range [1...10000]
Output Data
One line is printed on the console:
 If a combination is found whose sum of numbers equals the magic number:
o "Combination N:{sequence number} ({first number} + {second number} = {magic number})"
 If no combination matching the condition is found:
o "{number of all combinations} combinations - neither equals {magic number}"
Sample Input and Output
Input Output Comments Input Output
1 Combination All combinations of two numbers 88 Combination
10 N:4 (1 + 4 = between 1 and 10 are: 888 N:20025 (112 +
5 5) 1 1, 1 2, 1 3, 1 4, 1 5, ... 2 1, 2 2, ... 4 9, 4 1000 888 = 1000)
10, 5 1 ... 10 9, 10 10
The first combination whose sum of
numbers is equal to the magic number 5 is
the fourth (1 and 4)
Input Output Comments Input Output
23 4 combinations All combinations of two numbers 88 641601
24 - neither between 23 and 24 are: 23 23, 23 24, 24 888 combinations -
20 equals 20 23, 24 24 (total 4) 2000 neither equals
There are no pairs of numbers whose sum 2000
is equal to the magic 20

Testing in the Judge System


Test your solution in the online Judge system: https://judge.softuni.org/Contests/Compete/Index/4587#3

5. Traveling
Annie loves to travel and wants to visit several different destinations this year. When she chooses a destination, she
will decide how much money she will need to get there and start saving. When she has saved enough, she will be
able to travel.
Each time, the console will first read the destination and the minimum budget (a floating-point number) that will
be needed for the trip.
Then several sums (floating-point numbers) will be read that Annie saves by working and when she manages to
save enough for the trip, she will leave, and it should be printed on the console:
"Going to {destination}!"
When she has visited all the destinations she wants, instead of a destination she will enter "End" and the program
will end.

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 4 of 6


Sample Input and Output
Input Output Input Output
Greece Going to Greece! France Going to France!
1000.00 Going to Spain! 2000.00 Going to Portugal!
200.00 300.00 Going to Egypt!
200.00 300.00
300.00 200.00
100.00 400.00
150.00 190.00
240.00 258.00
Spain 360.00
1200.00 Portugal
300.00 1450.00
500.00 400.00
193.00 400.00
423.00 200.00
End 300.00
300.00
Egypt
1900.00
1000.00
280.00
300.00
500.00
End

Testing in the Judge System


Test your solution in the online Judge system: https://judge.softuni.org/Contests/Compete/Index/4587#4

6. Building
Write a function that outputs on the console the room numbers in a building (in descending order) when the
following conditions are met:
 On each even floor, there are only offices
 On each odd floor, there are only apartments
 Each apartment is marked as follows: A{floor number}{apartment number}, apartment numbers start from
0
 Each office is marked as follows: O{floor number}{office number}, office numbers also start from 0
 There are always apartments on the top floor, and they are bigger than the others, that is why they have 'L'
instead of 'A' in front of their number. If there is only one floor, there are only big apartments!
Two integers are read from the console – the number of floors and the number of rooms per floor.

Sample Input and Output


Input Output Comments

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 5 of 6


6 L60 L61 L62 L63 We have a total of 6 floors, with 4 rooms per floor. The odd floors have
4 A50 A51 A52 A53 only apartments, and even floors have only offices.
O40 O41 O42 O43
A30 A31 A32 A33
O20 O21 O22 O23
A10 A11 A12 A13
Input Output Input Output
9 L90 L91 L92 L93 L94 4 L40 L41 L42 L43
5 O80 O81 O82 O83 O84 4 A30 A31 A32 A33
A70 A71 A72 A73 A74 O20 O21 O22 O23
O60 O61 O62 O63 O64 A10 A11 A12 A13
A50 A51 A52 A53 A54
O40 O41 O42 O43 O44
A30 A31 A32 A33 A34
O20 O21 O22 O23 O24
A10 A11 A12 A13 A14

Testing in the Judge System


Test your solution in the online Judge system: https://judge.softuni.org/Contests/Compete/Index/4587#5

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 6 of 6

You might also like