QUALIFICATIONS FOR DISTRICT COMPETITIONS IN INFORMATICS
These problems serve to prepare elementary school students for the computer science competition. You can find qualifying problems for district competitions in Serbia here, and links to the website taken are provided in the notes with these examples. The notes also list the required prior knowledge for solving these tasks. Solutions are shown for some tasks.
1. FUEL
NOTE: - Task from the 1st round of qualifications, season 2022/2023. Taken from the website dms.rs/informatika-osnovne-skole/
Required prior knowledge: Data in C++, Operators in C++
Three families living in place A want to go on a trip to a distant city B. Each family travels in its own car and needs to fill up fuel before the trip, where it is necessary to always buy a whole number of liters of fuel at the pump. If the distance from place A to place B is known and if the fuel consumption of each car per 100 kilometers is known, determine the smallest total amount that all three families together need to buy in order for them all to reach city B.
Input:
From the standard input, first enter the whole number r (10 ≤ r ≤ 1000) which represents the distance from the place
A to place B (in kilometers) and then three integers p1, p2, p3 (2 ≤ pi ≤ 20) representing consumption
of every three cars per 100 kilometers.
Output:
Print the requested minimum amount of fuel on the standard output.
Example 1
Input
850
7
8
9
Output
205
Explanation
The first car needs 59.5 liters to travel 850 kilometers, so it will buy 60 liters, the second needs exactly 68 liters, and the third needs 76.5 liters, so it will buy 77 liters of gasoline, so all together will buy 60+68+ 77=205 liters of gasoline.
Example 2
Input
987
6
9
11
Output
258
Required prior knowledge: Data in C++, Operators in C++
Three families living in place A want to go on a trip to a distant city B. Each family travels in its own car and needs to fill up fuel before the trip, where it is necessary to always buy a whole number of liters of fuel at the pump. If the distance from place A to place B is known and if the fuel consumption of each car per 100 kilometers is known, determine the smallest total amount that all three families together need to buy in order for them all to reach city B.
Input:
From the standard input, first enter the whole number r (10 ≤ r ≤ 1000) which represents the distance from the place
A to place B (in kilometers) and then three integers p1, p2, p3 (2 ≤ pi ≤ 20) representing consumption
of every three cars per 100 kilometers.
Output:
Print the requested minimum amount of fuel on the standard output.
Example 1
Input
850
7
8
9
Output
205
Explanation
The first car needs 59.5 liters to travel 850 kilometers, so it will buy 60 liters, the second needs exactly 68 liters, and the third needs 76.5 liters, so it will buy 77 liters of gasoline, so all together will buy 60+68+ 77=205 liters of gasoline.
Example 2
Input
987
6
9
11
Output
258
2. KAKURO CHECK
NOTE: Task from the 1st round of qualifications for the 2022/23 season. Taken from the website dms.rs/informatika-osnovne-skole/
Required prior knowledge: Data in C++, Operators in C++, Branching in the program
In the Kakuro game, it is necessary to enter the numbers from 1 to 9 in the empty fields of the table in accordance with the predetermined totals of the types and columns, so that each total is obtained by adding different numbers. We will consider a simple variant of this game in which numbers are entered in 4 fields, arranged in two horizontal (water level) rows and two vertical (upright) columns, so that the sums of each row and each column are given in advance.
Write a program that checks whether the digits are entered according to the rules of the Kakuro game.
Input:
The first line of standard input contains two positive integers between 3 and 17 that represent the sums in each of the two columns. The next line contains two positive natural numbers between 3 and 17 that represent the sums in each type. After that, enter 4 numbers (given in two lines) that are written in the fields.
Output:
On the standard output, print that if the table is filled in correctly, that is. not if it isn't.
Example 1
Input
14 8
16 6
9 7
5 1
Output
Yes
Example 2
Input
11 9
17 3
9 8
3 1
Output
not
Required prior knowledge: Data in C++, Operators in C++, Branching in the program
In the Kakuro game, it is necessary to enter the numbers from 1 to 9 in the empty fields of the table in accordance with the predetermined totals of the types and columns, so that each total is obtained by adding different numbers. We will consider a simple variant of this game in which numbers are entered in 4 fields, arranged in two horizontal (water level) rows and two vertical (upright) columns, so that the sums of each row and each column are given in advance.
Write a program that checks whether the digits are entered according to the rules of the Kakuro game.
Input:
The first line of standard input contains two positive integers between 3 and 17 that represent the sums in each of the two columns. The next line contains two positive natural numbers between 3 and 17 that represent the sums in each type. After that, enter 4 numbers (given in two lines) that are written in the fields.
Output:
On the standard output, print that if the table is filled in correctly, that is. not if it isn't.
Example 1
Input
14 8
16 6
9 7
5 1
Output
Yes
Example 2
Input
11 9
17 3
9 8
3 1
Output
not
3. LIST OF PRODUCTS
NOTE: Problem from the 1st round of qualifications for the 2022/23 season. Taken from the website dms.rs/informatika-osnovne-skole/
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++
Every school day, Ljilja bought an apple, muffin or lollipop for a snack. If the price of each product is known and if the list of products she bought over several days is known, determine how much money she spent in total.
Input:
The prices of apples, muffins and lollipops (three natural numbers between 10 and 100, each in a separate row) are loaded from the standard input. After that, a string of up to 30 characters j, k and l is loaded, which determines the products that Ljilja bought, respectively.
Output:
Print the total amount of money spent on the standard output.
Example 1
Input
32
30
45
jjkllkl
Output
259
Example 2
Input
10
20
30
jkl
Output
60
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++
Every school day, Ljilja bought an apple, muffin or lollipop for a snack. If the price of each product is known and if the list of products she bought over several days is known, determine how much money she spent in total.
Input:
The prices of apples, muffins and lollipops (three natural numbers between 10 and 100, each in a separate row) are loaded from the standard input. After that, a string of up to 30 characters j, k and l is loaded, which determines the products that Ljilja bought, respectively.
Output:
Print the total amount of money spent on the standard output.
Example 1
Input
32
30
45
jjkllkl
Output
259
Example 2
Input
10
20
30
jkl
Output
60
4. A MASTER of his craft
NOTE: Task from the 1st round of qualifications for the 2022/23 season. Taken from the website dms.rs/informatika-osnovne-skole/
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++
After carrying out the work, the master Perry was returned n boxes with screws. The boxes are used and may contain different numbers of screws. Master Pera wants to use two boxes with the fewest number of screws. Help Master Perry to calculate the total number of screws in the two boxes so chosen.
Input:
In the first line of the standard input, the total number of boxes n (2 ≤ n ≤ 30) is entered. Then in the following n
line enter the numbers of screws in boxes ki (1 ≤ ki ≤ 100), respectively.
Output:
Print to standard output an integer representing the sum of the screws in the two boxes with the fewest screws.
Example 1
Input
5
45
32
9
15
67
Output
24
Example 2
Input
7
764
455
721
231
138
97
333
Output
235
Example 3
Input
5
28
14
30
15
14
Output
28
Input:
In the first line of the standard input, the total number of boxes n (2 ≤ n ≤ 30) is entered. Then in the following n
line enter the numbers of screws in boxes ki (1 ≤ ki ≤ 100), respectively.
Output:
Print to standard output an integer representing the sum of the screws in the two boxes with the fewest screws.
Example 1
Input
5
45
32
9
15
67
Output
24
Example 2
Input
7
764
455
721
231
138
97
333
Output
235
Example 3
Input
5
28
14
30
15
14
Output
28
INSTRUCTION:
The task can be solved using loops and branching in the program, but also in another way using vectors:
For the second way of solving it is necessary to know the following areas: Dynamic array-vector
The task can be solved using loops and branching in the program, but also in another way using vectors:
For the second way of solving it is necessary to know the following areas: Dynamic array-vector
Enter the data into a vector that stores data about the number of screws in each of the n boxes, and then sort the vector in ascending order, using the sort function from the <algorithm> header.
The first two values in the vector represent the number of screws in the boxes with the smallest number of screws.
The first two values in the vector represent the number of screws in the boxes with the smallest number of screws.
5. RAY
NOTE: Task from the 1st round of qualifications for the 2022/23 season. Taken from the website dms.rs/informatika-osnovne-skole/
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++ , Nested Loop in C++
Option: Dynamic array-vector
It is known that radio waves are disturbed by obstacles in their path. It is necessary to investigate whether radio waves can pass through a rectangular area where trees are planted. The radio wave is emitted from the upper left corner of that area in the direction determined by the vertical and horizontal displacement (these are the numbers that determine the difference between the coordinates of the next and current fields that the ray reached). For example, if the displacements are in the order of 2 and 1, this means that in each step the ray moves two rows down and one column to the right, and then in turn crosses fields whose coordinates (v, k) are equal to (0, 0), (2, 1), (4, 2) etc. Write a program that determines how many trees will be in the path of radio waves.
Input:
The first line of standard input contains the dimensions of the matrix bv and bk (3 ≤ bv, bk ≤ 100), separated by a space. After that, there is a description of the matrix, where fields containing trees are marked with 1, and fields that do not contain trees with 0. At the end, there is a line in which displacements are given (natural numbers separated by spaces).
Output:
Print the number of trees visited by the radio signal on the standard output.
Example 1
Input
8 8
0 1 1 0 0 1 0 1
0 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0
1 1 0 1 0 1 0 1
0 1 1 0 1 1 1 0
0 0 0 0 0 1 0 1
1 0 1 1 0 1 1 0
0 1 1 0 1 1 1 0
2 1
Output
2
Explanation
The picture shows the fields over which the ray will pass. Fields with trees are marked with the symbol X, and fields with no trees are marked with the symbol X.
- 1 1 0 0 1 0 1
0 0 1 0 1 0 1 0
1 - 1 0 1 0 1 0
1 1 0 1 0 1 0 1
0 1 X 0 1 1 1 0
0 0 0 0 0 1 0 1
1 0 1 X 0 1 1 0
0 1 1 0 1 1 1 0
Example 2
Input
8 8
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 2
Output
2
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++ , Nested Loop in C++
Option: Dynamic array-vector
It is known that radio waves are disturbed by obstacles in their path. It is necessary to investigate whether radio waves can pass through a rectangular area where trees are planted. The radio wave is emitted from the upper left corner of that area in the direction determined by the vertical and horizontal displacement (these are the numbers that determine the difference between the coordinates of the next and current fields that the ray reached). For example, if the displacements are in the order of 2 and 1, this means that in each step the ray moves two rows down and one column to the right, and then in turn crosses fields whose coordinates (v, k) are equal to (0, 0), (2, 1), (4, 2) etc. Write a program that determines how many trees will be in the path of radio waves.
Input:
The first line of standard input contains the dimensions of the matrix bv and bk (3 ≤ bv, bk ≤ 100), separated by a space. After that, there is a description of the matrix, where fields containing trees are marked with 1, and fields that do not contain trees with 0. At the end, there is a line in which displacements are given (natural numbers separated by spaces).
Output:
Print the number of trees visited by the radio signal on the standard output.
Example 1
Input
8 8
0 1 1 0 0 1 0 1
0 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0
1 1 0 1 0 1 0 1
0 1 1 0 1 1 1 0
0 0 0 0 0 1 0 1
1 0 1 1 0 1 1 0
0 1 1 0 1 1 1 0
2 1
Output
2
Explanation
The picture shows the fields over which the ray will pass. Fields with trees are marked with the symbol X, and fields with no trees are marked with the symbol X.
- 1 1 0 0 1 0 1
0 0 1 0 1 0 1 0
1 - 1 0 1 0 1 0
1 1 0 1 0 1 0 1
0 1 X 0 1 1 1 0
0 0 0 0 0 1 0 1
1 0 1 X 0 1 1 0
0 1 1 0 1 1 1 0
Example 2
Input
8 8
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 2
Output
2
INSTRUCTION:
Use nested loops to load the matrix.
Start from position (0,0). Using a loop, while checking the condition that you are inside the matrix, move for the entered row and column shift values to new positions. If at those positions the value in the matrix is equal to 1, increase the counter (integer variable representing the required number) by 1.
After exiting the loop, the number obtained is actually the number of fields on which the tree is located.
Use nested loops to load the matrix.
Start from position (0,0). Using a loop, while checking the condition that you are inside the matrix, move for the entered row and column shift values to new positions. If at those positions the value in the matrix is equal to 1, increase the counter (integer variable representing the required number) by 1.
After exiting the loop, the number obtained is actually the number of fields on which the tree is located.
6. NUMBER OF DAYS OF MEASURED TRAINING
NOTE: Task from the 1st round of qualifications for the 2022/23 season. Taken from the website dms.rs/informatika-osnovne-skole/
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++ ,
When preparing for upcoming competitions, the athlete measures the result he has achieved every day. Since he wants to improve his form evenly, he wants the result to be better every day (a higher number means a better result). For a certain day of training, we will say it is good, if the result achieved on that day is strictly better than the previous one, and strictly worse than the next one (for it to be good, it is enough for the first day that it is strictly worse than the next one, and for the last day that it is strictly better than the previous one).
Write a program that calculates the number of good days.
Input:
The number of days n(3 ≤ n ≤ 100) during which the athlete trained is loaded from the standard input, and in
in the second row, the results that the athlete achieved during each of those n days.
Output:
Print the number of good days to the standard output.
Example 1
Input
6
100 120 130 110 140 150
Ootput
4
Example 2
Input
6
10 20 30 40 50 60
Output
6
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++ ,
When preparing for upcoming competitions, the athlete measures the result he has achieved every day. Since he wants to improve his form evenly, he wants the result to be better every day (a higher number means a better result). For a certain day of training, we will say it is good, if the result achieved on that day is strictly better than the previous one, and strictly worse than the next one (for it to be good, it is enough for the first day that it is strictly worse than the next one, and for the last day that it is strictly better than the previous one).
Write a program that calculates the number of good days.
Input:
The number of days n(3 ≤ n ≤ 100) during which the athlete trained is loaded from the standard input, and in
in the second row, the results that the athlete achieved during each of those n days.
Output:
Print the number of good days to the standard output.
Example 1
Input
6
100 120 130 110 140 150
Ootput
4
Example 2
Input
6
10 20 30 40 50 60
Output
6
7. COOKERMAN
NOTE: Task from the 1st round of qualifications for the 2022/23 season. Taken from the website dms.rs/informatika-osnovne-skole/
Required prior knowledge: Data in C++, Operators in C++
For one portion, the chef needs m grams of meat for the main course (in addition to other ingredients), and for the salad either k grams of cabbage or c grams of beets. There are grams of meat, grams of cabbage and C grams of beets available (and all the other ingredients are much more). Write a program that loads the required quantities for one portion m, k, c, and then the available quantities of MKC, and prints out how many whole portions (main dish and salad) the chef has enough ingredients for.
Input:
The standard input has the numbers m, k, c, M, K, C, each in a separate row. All numbers are integers,
positive and less than 50000.
Output:
Print only one whole unsigned number on the standard output, which is the number of whole portions that can be given
are prepared.
Example 1
Input
200
250
150
2200
1400
890
Output
10
Example 2
input
150
200
100
6100
5100
1000
Output
35
Required prior knowledge: Data in C++, Operators in C++
For one portion, the chef needs m grams of meat for the main course (in addition to other ingredients), and for the salad either k grams of cabbage or c grams of beets. There are grams of meat, grams of cabbage and C grams of beets available (and all the other ingredients are much more). Write a program that loads the required quantities for one portion m, k, c, and then the available quantities of MKC, and prints out how many whole portions (main dish and salad) the chef has enough ingredients for.
Input:
The standard input has the numbers m, k, c, M, K, C, each in a separate row. All numbers are integers,
positive and less than 50000.
Output:
Print only one whole unsigned number on the standard output, which is the number of whole portions that can be given
are prepared.
Example 1
Input
200
250
150
2200
1400
890
Output
10
Example 2
input
150
200
100
6100
5100
1000
Output
35
8. DICE STAIRCASE
NOTE: Task from the 1st round of qualifications for the 2022/23 season. Taken from the website dms.rs/informatika-osnovne-skole/
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++
Two others are playing with dice. They have two pillars left from the previous game whose heights are A and B. Now, they have two ideas for the new building. According to one idea, they need columns of height A1 and B1, and according to another, columns of height A2 and B2. To change the height of a column by 1, one of the friends needs Tx time and the other Ty time. In what minimum time can the friends remodel (lengthen or shorten) the existing pillars and make them into pillars that fit one of the ideas, if each of them remodels one pillar? Time
is measured from the moment when the friends start the alterations at the same time, until the moment when both of them have finished.
Input:
In the four lines of the standard input, there are two natural numbers separated by a space. In the first row are A and B, in the second A1 and B1, in the third A2 and B2, all from the interval [1, 1000000], and in the fourth Tx and Ty, from the interval [1, 100].
Output: Print one natural number on the standard output, the required minimum time.
Example 1
input
10 20
18 28
21 31
1 10
Output
20
Example 2
Input
7 4
9 13
14 12
3 2
Output
15
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++
Two others are playing with dice. They have two pillars left from the previous game whose heights are A and B. Now, they have two ideas for the new building. According to one idea, they need columns of height A1 and B1, and according to another, columns of height A2 and B2. To change the height of a column by 1, one of the friends needs Tx time and the other Ty time. In what minimum time can the friends remodel (lengthen or shorten) the existing pillars and make them into pillars that fit one of the ideas, if each of them remodels one pillar? Time
is measured from the moment when the friends start the alterations at the same time, until the moment when both of them have finished.
Input:
In the four lines of the standard input, there are two natural numbers separated by a space. In the first row are A and B, in the second A1 and B1, in the third A2 and B2, all from the interval [1, 1000000], and in the fourth Tx and Ty, from the interval [1, 100].
Output: Print one natural number on the standard output, the required minimum time.
Example 1
input
10 20
18 28
21 31
1 10
Output
20
Example 2
Input
7 4
9 13
14 12
3 2
Output
15
9. GLOSSARY
NOTE: Task from the 1st round of qualifications for the 2022/23 season. Taken from the website dms.rs/informatika-osnovne-skole/
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++ ,Stringovi u C/C++ jeziku
Ana is learning to make words from letters. Today, she wants to make as many examples of the word she came up with from the letters she has available. Write a program that determines how many times a given word can be formed from the letters of a given collection.
Input:
In the first line of standard input there is a string of characters representing a collection, and in the second line a string representing a word. Both strings consist exclusively of lowercase letters of the English alphabet and are up to 50,000 characters long.
Output:
Print one whole number on the standard output, the number of possible combinations of the given word.
Example 1
input
matematikaiprogramiranje
meta
Exit
2
Example 2
Input
nekavelikakolekcijaslova
kea
Output
3
Example 3
Input
babanedanijevisesedapajenekogleda
deda
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++ ,Stringovi u C/C++ jeziku
Ana is learning to make words from letters. Today, she wants to make as many examples of the word she came up with from the letters she has available. Write a program that determines how many times a given word can be formed from the letters of a given collection.
Input:
In the first line of standard input there is a string of characters representing a collection, and in the second line a string representing a word. Both strings consist exclusively of lowercase letters of the English alphabet and are up to 50,000 characters long.
Output:
Print one whole number on the standard output, the number of possible combinations of the given word.
Example 1
input
matematikaiprogramiranje
meta
Exit
2
Example 2
Input
nekavelikakolekcijaslova
kea
Output
3
Example 3
Input
babanedanijevisesedapajenekogleda
deda
10. DOG PUKI
NOTE: Task from the 1st round of qualifications for the 2022/23 season. Taken from the website dms.rs/informatika-osnovne-skole/
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++ , Strings in C++
Option: Dynamic array-vector
Dog Puki is the smartest dog in the world. In addition to being able to perform various acrobatic tricks, he is also an excellent programmer, so he invented a new programming language that he named P++.
Each line of program code in the Ć++ language consists of exactly m integers separated by spaces. Since P++ is a very advanced language, it needs to be translated so that it can be understood by today's computers. In the translation process, at some point each line of code needs to be transformed to contain m of the same integers. The line is transformed by incrementing or decrementing each number by 1 until the desired number is reached, and the cost of transforming one number to another is the increment/decrement number.
Let's say we want to transform the line “1 4 9” into “3 3 3”.
• We need to increase the number 1 by 2 times to get the number 3, so the cost of that transformation is 2.
• We need to reduce the number 4 once, so the cost of the transformation is 1.
• We need to reduce the number 9 6 times to get the desired number 3, so the cost of transforming that number is
The total cost of the line transformation is 2 + 1 + 6 = 9.
In order to save translation resources, it is necessary to transform the code so that the total transformation cost is as low as possible. For one loaded line, it is necessary to determine to which number it will be transformed in order to make the cost of the transformation the lowest possible. In the event that the line can be transformed into several different numbers so that the price remains the same, the transformation into the largest such number is performed.
Input:
In the first line of the standard input there is a natural number m (1 ≤ m ≤ 105 ) which indicates how many numbers are in the line to be loaded. The next line contains a sequence of m integers (between -1000 and 1000) separated by spaces that represent one line in Ć++.
Additional restrictions: * In test examples worth 49 points, m ≤ 100 applies additionally.
Output:
In the first line of the standard output, print a number that indicates the number into which the numbers in the given line will be transformed. In the second line of the standard output, print the lowest cost of the transformation of the given line of program code.
Example 1
Input
6
1 8 6 -4 0 7
Output
6
24
Explanation
The lowest transformation cost is achieved if all numbers are transformed into the number 6. The transformation cost of the line is: |1 − 6| + |8 − 6| + |6 − 6| + | − 4 − 6| + |0 − 6| + |7 − 6| = 24. Notice that the same price would be obtained if we transformed the line into the number 1, but the number 6 is larger, so we choose it.
Example 2
Input
7
-5 -4 -3 -2 -1 0 1
Output
-2
12
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++ , Strings in C++
Option: Dynamic array-vector
Dog Puki is the smartest dog in the world. In addition to being able to perform various acrobatic tricks, he is also an excellent programmer, so he invented a new programming language that he named P++.
Each line of program code in the Ć++ language consists of exactly m integers separated by spaces. Since P++ is a very advanced language, it needs to be translated so that it can be understood by today's computers. In the translation process, at some point each line of code needs to be transformed to contain m of the same integers. The line is transformed by incrementing or decrementing each number by 1 until the desired number is reached, and the cost of transforming one number to another is the increment/decrement number.
Let's say we want to transform the line “1 4 9” into “3 3 3”.
• We need to increase the number 1 by 2 times to get the number 3, so the cost of that transformation is 2.
• We need to reduce the number 4 once, so the cost of the transformation is 1.
• We need to reduce the number 9 6 times to get the desired number 3, so the cost of transforming that number is
The total cost of the line transformation is 2 + 1 + 6 = 9.
In order to save translation resources, it is necessary to transform the code so that the total transformation cost is as low as possible. For one loaded line, it is necessary to determine to which number it will be transformed in order to make the cost of the transformation the lowest possible. In the event that the line can be transformed into several different numbers so that the price remains the same, the transformation into the largest such number is performed.
Input:
In the first line of the standard input there is a natural number m (1 ≤ m ≤ 105 ) which indicates how many numbers are in the line to be loaded. The next line contains a sequence of m integers (between -1000 and 1000) separated by spaces that represent one line in Ć++.
Additional restrictions: * In test examples worth 49 points, m ≤ 100 applies additionally.
Output:
In the first line of the standard output, print a number that indicates the number into which the numbers in the given line will be transformed. In the second line of the standard output, print the lowest cost of the transformation of the given line of program code.
Example 1
Input
6
1 8 6 -4 0 7
Output
6
24
Explanation
The lowest transformation cost is achieved if all numbers are transformed into the number 6. The transformation cost of the line is: |1 − 6| + |8 − 6| + |6 − 6| + | − 4 − 6| + |0 − 6| + |7 − 6| = 24. Notice that the same price would be obtained if we transformed the line into the number 1, but the number 6 is larger, so we choose it.
Example 2
Input
7
-5 -4 -3 -2 -1 0 1
Output
-2
12
11. THE DATE WITH THE HIGHEST EARNINGS
NOTE: Task from the 1st round of qualifications for the 2022/23 season. Taken from the website dms.rs/informatika-osnovne-skole/
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++ , Strings in C++
Option: Dynamic array-vector, Dictionary of data-maps in C++
All fiscal invoices issued by a bookstore are known. From each invoice, you can read the date when the invoice was issued and the amount charged. Write a program that determines the highest total amount charged by the bookstore in one day, i.e. the maximum daily market, as well as the date when that amount was the highest (if there are several such dates, write them all, arranged chronologically from the first to the last date).
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++ , Strings in C++
Option: Dynamic array-vector, Dictionary of data-maps in C++
All fiscal invoices issued by a bookstore are known. From each invoice, you can read the date when the invoice was issued and the amount charged. Write a program that determines the highest total amount charged by the bookstore in one day, i.e. the maximum daily market, as well as the date when that amount was the highest (if there are several such dates, write them all, arranged chronologically from the first to the last date).
Input
From the standard input, the number of issued invoices n (1≤n≤105) is loaded, followed by data on each invoice in the form dd-mm-yyyy amount, where the amount is a real number rounded to two decimal places.
Output
Print the maximum amount (a real number rounded to two decimal places) on the standard output, and then in the following lines the dates when that maximum amount was charged. If there are multiple dates, they should be listed in order from oldest to newest.
Example
Input
5
03-07-2021 340.00
05-04-2021 285.50
03-07-2021 100.50
04-07-2021 270.00
04-05-2021 155.00
Output
440.50
05-04-2021
03-07-2021
From the standard input, the number of issued invoices n (1≤n≤105) is loaded, followed by data on each invoice in the form dd-mm-yyyy amount, where the amount is a real number rounded to two decimal places.
Output
Print the maximum amount (a real number rounded to two decimal places) on the standard output, and then in the following lines the dates when that maximum amount was charged. If there are multiple dates, they should be listed in order from oldest to newest.
Example
Input
5
03-07-2021 340.00
05-04-2021 285.50
03-07-2021 100.50
04-07-2021 270.00
04-05-2021 155.00
Output
440.50
05-04-2021
03-07-2021
12. TOTALS AFTER DIVISION
NOTE: Problem from the 1st round of qualifications for district competition in informatics in the 2022/23 season. Taken from the website dms.rs/informatika-osnovne-skole/
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++ , Arrays in C/C++
Optional: Maximum sum of substrings
A sequence of integers of length n is given. The string needs to be cut into two parts. After cutting, it is determined how many pairs of numbers exist such that one number is from the left and the other from the right and that their sum is an even number. Determine the maximum number of such pairs that can be obtained by cutting the sequence.
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++ , Arrays in C/C++
Optional: Maximum sum of substrings
A sequence of integers of length n is given. The string needs to be cut into two parts. After cutting, it is determined how many pairs of numbers exist such that one number is from the left and the other from the right and that their sum is an even number. Determine the maximum number of such pairs that can be obtained by cutting the sequence.
Input
The integer n (2≤n≤50000) is entered from the standard input. Then, in the next line, the elements of the sequence a and (0≤ai≤100) are entered, separated by a space.
Output
Print a single integer representing the requested value to the standard output.
Example 1
Input
8
1 7 3 4 6 5 8 0
Output
7
Explanation: The largest number of pairs is obtained by dividing the sequence into parts 1 7 3 4 6 and 5 8 0. The pairs are (1,5), (7,5), (3,5), (4,8), (4, 0), (6,8) and (6,0).
Example 2
Input
7
1 9 3 11 12 4 8
Output
4
The integer n (2≤n≤50000) is entered from the standard input. Then, in the next line, the elements of the sequence a and (0≤ai≤100) are entered, separated by a space.
Output
Print a single integer representing the requested value to the standard output.
Example 1
Input
8
1 7 3 4 6 5 8 0
Output
7
Explanation: The largest number of pairs is obtained by dividing the sequence into parts 1 7 3 4 6 and 5 8 0. The pairs are (1,5), (7,5), (3,5), (4,8), (4, 0), (6,8) and (6,0).
Example 2
Input
7
1 9 3 11 12 4 8
Output
4
13. ARRAY PERMUTATIONS
NOTE: Task from the 3st round of qualifications for the 2022/23 season. Taken from the website dms.rs/informatika-osnovne-skole/
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++ , Arrays in C/C++
Optional: Fast scaling algorithm
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++ , Arrays in C/C++
Optional: Fast scaling algorithm
We have a shuffler that can shuffle the order of array elements. The mixer always mixes the elements in the same way. Let the sequence obtained by shuffling the sequence 0 1 2 ... n-1 be given. Write a program that determines the sequence obtained by shuffling the sequence 0 1 2 ... n-1
m times.
Input
Natural numbers n (1≤ n ≤50000) and m (0≤ m ≤10 ^ 18) separated by a space are entered from the standard input. It is entered in the next line
n different numbers between 0 and n−1 separated by a space, representing the elements of the sequence 0 1 2 ... n-1 after one shuffle.
Output
Print to standard output
n different natural numbers between 0 and n−1 separated by a space representing the elements of the sequence 0 1 2 ... n-1 after
m mixing.
Example 1
Input
4 2
0 2 3 1
Output
0 3 1 2
Explanation: The starting sequence is 0 1 2 3. The first shuffle gives 0 2 3 1. The second shuffle gives 0 3 1 2.
Example 2
Input
5 3
1 2 0 4 3
Output
0 1 2 4 3
Explanation: The starting sequence is 0 1 2 3 4. The first shuffle yields 1 2 0 4 3. The second shuffle yields 2 0 1 3 4. The third shuffle yields 0 1 2 4 3.
Example 3
Input
4 3
1 0 3 2
Output
1 0 3 2
Explanation: The starting sequence is 0 1 2 3. The first shuffle produces 1 0 3 2. The second shuffle produces 0 1 2 3. The third shuffle produces 1 0 3 2.
m times.
Input
Natural numbers n (1≤ n ≤50000) and m (0≤ m ≤10 ^ 18) separated by a space are entered from the standard input. It is entered in the next line
n different numbers between 0 and n−1 separated by a space, representing the elements of the sequence 0 1 2 ... n-1 after one shuffle.
Output
Print to standard output
n different natural numbers between 0 and n−1 separated by a space representing the elements of the sequence 0 1 2 ... n-1 after
m mixing.
Example 1
Input
4 2
0 2 3 1
Output
0 3 1 2
Explanation: The starting sequence is 0 1 2 3. The first shuffle gives 0 2 3 1. The second shuffle gives 0 3 1 2.
Example 2
Input
5 3
1 2 0 4 3
Output
0 1 2 4 3
Explanation: The starting sequence is 0 1 2 3 4. The first shuffle yields 1 2 0 4 3. The second shuffle yields 2 0 1 3 4. The third shuffle yields 0 1 2 4 3.
Example 3
Input
4 3
1 0 3 2
Output
1 0 3 2
Explanation: The starting sequence is 0 1 2 3. The first shuffle produces 1 0 3 2. The second shuffle produces 0 1 2 3. The third shuffle produces 1 0 3 2.
SOLUTION:
The task can be solved using a "brute force" algorithm that works for most input data, except for a large set number of required permutations of the initial string. A more efficient solution will be obtained if the transformation scheme is permuted and finally the transformed scheme is used to permute the initial sequence. It is, in fact, an application of the rapid scaling algorithm: For a better understanding of both solutions, see the attached video, which does not show the solution as code. For the complete solution, click the "Solution" button. |
|
14. PADLOCK
NOTE: Task from the 2nd round of qualifications for the 2022/23 season. Assignment for 7th grade. Taken from the website dms.rs/informatika-osnovne-skole/
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++
A bicycle lock has a four-digit code. Each digit is set by rotating the ring on which all ten digits are written.
Write a program that, given the correct code entered and the currently set code on the padlock, determines the minimum number of turns of the ring needed to unlock the padlock.
Input
From the standard input, a four-digit number (can start with zeros) is loaded that represents the correct code, and then a four-digit number (can start with zeros) that represents the initial position of the ring on the padlock.
Output
Print the smallest number of turns of the rings on the standard output.
Example 1
Input
1234
7249
Exit
10
Explanation
We can turn the ring with 7 forward 4 times to get to the digit 1 (from 7 to 8, from 8 to 9, from 9 to 0 and from 0 to 1).
We don't have to turn the ring that says 2.
We can turn the ring that says 4 backwards once to get to the number 3.
The ring that says 9 can be turned 5 times (either forward or backward) to get to the number 4.
Example 2
Input
4812
0319
Output
12
Write a program that, given the correct code entered and the currently set code on the padlock, determines the minimum number of turns of the ring needed to unlock the padlock.
Input
From the standard input, a four-digit number (can start with zeros) is loaded that represents the correct code, and then a four-digit number (can start with zeros) that represents the initial position of the ring on the padlock.
Output
Print the smallest number of turns of the rings on the standard output.
Example 1
Input
1234
7249
Exit
10
Explanation
We can turn the ring with 7 forward 4 times to get to the digit 1 (from 7 to 8, from 8 to 9, from 9 to 0 and from 0 to 1).
We don't have to turn the ring that says 2.
We can turn the ring that says 4 backwards once to get to the number 3.
The ring that says 9 can be turned 5 times (either forward or backward) to get to the number 4.
Example 2
Input
4812
0319
Output
12
15. CORRECT EXPRESSION
16. DICE STAIRCASE
NOTE: Task from the 1nd round of qualifications for the 2022/23 season. Assignment for 8th grade. Taken from the website dms.rs/informatika-osnovne-skole/
Required prior knowledge: Data in C++, Operators in C++, Built-in functions min, max, abs
Two others are playing with dice. They have two pillars left from the previous game whose heights are A and B. Now, they have two ideas for the new building. According to one idea, they need columns of height A1 and B1, and according to another, columns of height A2 and B2. To change the height of a column by 1, one of the friends needs Tx time and the other Ty time. In what minimum time can the friends remodel (lengthen or shorten) the existing pillars and make them into pillars that fit one of the ideas, if each of them remodels one pillar? The time is measured from the moment when the friends simultaneously start the alterations, until the moment when both of them have finished.
Input:
In the four lines of the standard input, there are two natural numbers separated by a space. In the first row are A and B, in the second A1 and B1, in the third A2 and B2, all from the interval [1, 1000000], and in the fourth Tx and Ty, from the interval [1, 100].
Output:
Print one natural number on the standard output, the required minimum time.
Example 1
Input
10 20
18 28
21 31
1 10
Output
20
Example 2
Input
7 4
9 13
14 12
3 2
Output
15
Required prior knowledge: Data in C++, Operators in C++, Built-in functions min, max, abs
Two others are playing with dice. They have two pillars left from the previous game whose heights are A and B. Now, they have two ideas for the new building. According to one idea, they need columns of height A1 and B1, and according to another, columns of height A2 and B2. To change the height of a column by 1, one of the friends needs Tx time and the other Ty time. In what minimum time can the friends remodel (lengthen or shorten) the existing pillars and make them into pillars that fit one of the ideas, if each of them remodels one pillar? The time is measured from the moment when the friends simultaneously start the alterations, until the moment when both of them have finished.
Input:
In the four lines of the standard input, there are two natural numbers separated by a space. In the first row are A and B, in the second A1 and B1, in the third A2 and B2, all from the interval [1, 1000000], and in the fourth Tx and Ty, from the interval [1, 100].
Output:
Print one natural number on the standard output, the required minimum time.
Example 1
Input
10 20
18 28
21 31
1 10
Output
20
Example 2
Input
7 4
9 13
14 12
3 2
Output
15
17. PLUMS
NOTE: Task from the 2nd round of qualifications for the 2022/23 season. Assignment for 6th grade. Taken from the website dms.rs/informatika-osnovne-skole/
Required prior knowledge: Data in C++, Operators in C++, Branching in the program
Janko and Nataša were eating plums. They took two plums from the bowl at the same time, Janko two at a time, and Natasha three at a time, as long as it was possible, that is. until there are less than five plums left. The remaining plums (if there were any) were later eaten by Marko. Write a program that loads the number of plums at the beginning, and prints how many people ate, as well as the number of those who ate at least one plum.
Input
On the standard input there is one whole unsigned number less than 51, the number of plums at the beginning.
Output
Print one integer in four lines to the standard output. The first three numbers should be the numbers of plums eaten by Janko, Nataša and Marko, in that order. The fourth number should be the number of those who ate at least one plum.
Example 1
Input
14
Output
4
6
4
3
Example 2
Input
3
Output
0
0
3
1
Required prior knowledge: Data in C++, Operators in C++, Branching in the program
Janko and Nataša were eating plums. They took two plums from the bowl at the same time, Janko two at a time, and Natasha three at a time, as long as it was possible, that is. until there are less than five plums left. The remaining plums (if there were any) were later eaten by Marko. Write a program that loads the number of plums at the beginning, and prints how many people ate, as well as the number of those who ate at least one plum.
Input
On the standard input there is one whole unsigned number less than 51, the number of plums at the beginning.
Output
Print one integer in four lines to the standard output. The first three numbers should be the numbers of plums eaten by Janko, Nataša and Marko, in that order. The fourth number should be the number of those who ate at least one plum.
Example 1
Input
14
Output
4
6
4
3
Example 2
Input
3
Output
0
0
3
1
18. BOTTLES
NOTE: Task from the 2nd round of qualifications for the 2022/23 season. Assignment for 6th grade. Taken from the website dms.rs/informatika-osnovne-skole/
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++
Ranko pours various types of liquids from n full canisters of different volumes into V liter bottles. For each canister, determine how many bottles will be completely filled with liquid from that canister, as well as how much liquid will remain in the canister when those bottles are filled. Liquids must not mix with each other.
Input
In the first line of the standard input there are 2 integers n (number of canisters) and v (volume of water in liters). The next n lines contain one integer. Each number represents the volume of one canister in liters. All numbers are integers and between 1 and 10000.
Output
Write 2 integers in n rows. The first number represents the number of bottles that will be completely filled by the canister, and the second number is how many liters of liquid will remain in the canister after filling the bottles.
Example
Input
7 6
24
13
6
10
17
23
40
Output
4 0
2 1
1 0
1 4
2 5
3 5
6 4
Explanation
The first canister has a volume of 24 liters Since the volume of the bottle is 6 liters, 4 bottles can be filled and 0 liters remain in the canister. The second canister has a volume of 13 liters, so 2 bottles can be filled, and 1 liter remains in the canister. Similarly for other canisters.
Required prior knowledge: Data in C++, Operators in C++, Branching in the program, Loops in C++
Ranko pours various types of liquids from n full canisters of different volumes into V liter bottles. For each canister, determine how many bottles will be completely filled with liquid from that canister, as well as how much liquid will remain in the canister when those bottles are filled. Liquids must not mix with each other.
Input
In the first line of the standard input there are 2 integers n (number of canisters) and v (volume of water in liters). The next n lines contain one integer. Each number represents the volume of one canister in liters. All numbers are integers and between 1 and 10000.
Output
Write 2 integers in n rows. The first number represents the number of bottles that will be completely filled by the canister, and the second number is how many liters of liquid will remain in the canister after filling the bottles.
Example
Input
7 6
24
13
6
10
17
23
40
Output
4 0
2 1
1 0
1 4
2 5
3 5
6 4
Explanation
The first canister has a volume of 24 liters Since the volume of the bottle is 6 liters, 4 bottles can be filled and 0 liters remain in the canister. The second canister has a volume of 13 liters, so 2 bottles can be filled, and 1 liter remains in the canister. Similarly for other canisters.
19. FOOTBALL GROUP - TABLE
NOTE: Task from the 2nd round of qualifications for the 2022/23 season. Assignment for 6th grade. Taken from the website dms.rs/informatika-osnovne-skole/
Required prior knowledge: Data in C++, Operators in C++, Abbreviated if-else statement(Operator "? :")
At the World Cup in football, each group consists of 4 teams that play each other. The two best placed teams advance to the next stage of the competition. 3 points are awarded for each win, and 1 point for a draw. Write a program that, based on the results of 6 games, determines the number of points for each team and the goal difference (the difference between the number of goals scored and the number of goals conceded).
Input
From the standard input, the results of all matches are entered in the order AB, CD, AC, BD, AD, BC. Each result is entered as two numbers separated by a space.
Output
Print the number of points and goal difference for teams A, B, C and D respectively on the standard output.
Example 1
Input
3 2
2 1
4 2
1 3
3 0
1 0
Output
9 6
3 -2
3 -2
3 -2
Example 2
Input
0 0
2 0
6 2
1 1
3 0
1 0
Output
7 7
5 1
3 -3
1 -5
Required prior knowledge: Data in C++, Operators in C++, Abbreviated if-else statement(Operator "? :")
At the World Cup in football, each group consists of 4 teams that play each other. The two best placed teams advance to the next stage of the competition. 3 points are awarded for each win, and 1 point for a draw. Write a program that, based on the results of 6 games, determines the number of points for each team and the goal difference (the difference between the number of goals scored and the number of goals conceded).
Input
From the standard input, the results of all matches are entered in the order AB, CD, AC, BD, AD, BC. Each result is entered as two numbers separated by a space.
Output
Print the number of points and goal difference for teams A, B, C and D respectively on the standard output.
Example 1
Input
3 2
2 1
4 2
1 3
3 0
1 0
Output
9 6
3 -2
3 -2
3 -2
Example 2
Input
0 0
2 0
6 2
1 1
3 0
1 0
Output
7 7
5 1
3 -3
1 -5
20. THE MOST EXCELLENT STUDENTS
NOTE: Task from the 2nd round of qualifications for the 2022/23 season. Assignment for 6th grade. Taken from the website dms.rs/informatika-osnovne-skole/
Required prior knowledge: Data in C++, Operators in C++, Array in C++, determining the maximum, when the element is the same as the position
Write a program that, for a given class and the success of each of n students, prints the class with the most excellent students.
Input
The first line of the standard input contains the integer n(1≤n≤100). In each of the next n lines there is one natural and one real number separated by a space. A natural number is from the interval [1,8] and represents the class, and a real number is from the interval [1.0,5.0] and represents success. A number equal to or greater than 4.5 represents an excellent achievement.
Output
Print one whole number on the standard output, the number of the class with the most excellent students. If the answer is not clear, write the number of the largest class with the most excellent students.
Example
Input
6
4 3.58
4 4.67
5 4.83
6 4.5
4 4.93
6 5.0
Output
6
Required prior knowledge: Data in C++, Operators in C++, Array in C++, determining the maximum, when the element is the same as the position
Write a program that, for a given class and the success of each of n students, prints the class with the most excellent students.
Input
The first line of the standard input contains the integer n(1≤n≤100). In each of the next n lines there is one natural and one real number separated by a space. A natural number is from the interval [1,8] and represents the class, and a real number is from the interval [1.0,5.0] and represents success. A number equal to or greater than 4.5 represents an excellent achievement.
Output
Print one whole number on the standard output, the number of the class with the most excellent students. If the answer is not clear, write the number of the largest class with the most excellent students.
Example
Input
6
4 3.58
4 4.67
5 4.83
6 4.5
4 4.93
6 5.0
Output
6
21. VALLEYS
A series of elevations of some terrain is given. A valley is a subsequence of equal successive heights such that the height before it and the height after it are strictly greater than it. Write a program that determines how many valleys there are on a given terrain.
Input
The number of terrain parts n (1≤n≤150) is entered from the standard input. In the next line, n numbers are entered, separated by a space, which represent the elevations of the terrain. All heights are integers from the interval [0,100]
Output
Print one integer representing the number of valleys to the standard output.
Example 1
Input
8
5 3 3 7 4 4 4 8
Output
2
Explanation: The valleys are 5 3 3 7 and 7 4 4 4 8.
Example 2
Input
5
4 3 1 2 4
Output
1
Explanation: The only valley is 3 1 2.
Example 3
Input
11
2 2 3 4 4 2 2 2 5 4 5
Output
2
Explanation: The valleys are 4 2 2 2 5 and 5 4 5.
Input
The number of terrain parts n (1≤n≤150) is entered from the standard input. In the next line, n numbers are entered, separated by a space, which represent the elevations of the terrain. All heights are integers from the interval [0,100]
Output
Print one integer representing the number of valleys to the standard output.
Example 1
Input
8
5 3 3 7 4 4 4 8
Output
2
Explanation: The valleys are 5 3 3 7 and 7 4 4 4 8.
Example 2
Input
5
4 3 1 2 4
Output
1
Explanation: The only valley is 3 1 2.
Example 3
Input
11
2 2 3 4 4 2 2 2 5 4 5
Output
2
Explanation: The valleys are 4 2 2 2 5 and 5 4 5.
HOROSCOPE
The example from the 2nd round of the 2019/20 season qualifications was downloaded from the website dms.rs/informatika-osnovne-skole/
The unique identity number of citizens (abbreviated JMBG) is a series of 13 digits, which in our country everyone receives as a very young child. The first two digits of this string represent the day and the next two the month of birth. For example, if someone's JMBG starts with 0904, they were born on the ninth of April, and if it starts with 3112, they were born on the thirty-first of December.
Perica likes to have fun reading various horoscopes, and at one point he wondered how many people there are born in each of the zodiac signs, for whom what is written in the horoscope should apply. Perica somehow managed to get a larger list of birth numbers, and he knows the start and end dates for each character:
• ARIES – from March 21 to April 20
• TAURUS - from April 21 to May 21
• GEMINI – from May 22 to June 21
• CANCER – from June 22 to July 22
• LEO - from July 23 to August 22
• VIRGO – from August 23 to September 22
• LIBRA – from September 23 to October 23
• SCORPIO - from October 24 to November 22
• SAGITTARIUS - from November 23 to December 21
• CAPRICORN – from December 22 to January 20
• AQUARIUS – from January 21 to February 19
• PISCES – from February 20 to March 20
Perica now wants to count the births in each of the zodiac signs. Write a program that helps Perica count.
Input: The first line of the standard input contains the number N (1 ≤ N ≤ 200), the number of registration numbers that Perica has acquired. In each of the next N lines there is one registration number (13 digits without spaces).
Output: Print 12 integers to standard output, each in a separate line. The first number is the number of people born under the sign of the ram, the second - under the sign of the bull, etc. The last, twelfth number is the number of people born under the sign of fish.
Example 1
Input
5
1504279718463
0412622712918
1903326718649
0710262713307
0104646719372
Output
2
0
0
0
0
0
1
0
1
0
0
1
The unique identity number of citizens (abbreviated JMBG) is a series of 13 digits, which in our country everyone receives as a very young child. The first two digits of this string represent the day and the next two the month of birth. For example, if someone's JMBG starts with 0904, they were born on the ninth of April, and if it starts with 3112, they were born on the thirty-first of December.
Perica likes to have fun reading various horoscopes, and at one point he wondered how many people there are born in each of the zodiac signs, for whom what is written in the horoscope should apply. Perica somehow managed to get a larger list of birth numbers, and he knows the start and end dates for each character:
• ARIES – from March 21 to April 20
• TAURUS - from April 21 to May 21
• GEMINI – from May 22 to June 21
• CANCER – from June 22 to July 22
• LEO - from July 23 to August 22
• VIRGO – from August 23 to September 22
• LIBRA – from September 23 to October 23
• SCORPIO - from October 24 to November 22
• SAGITTARIUS - from November 23 to December 21
• CAPRICORN – from December 22 to January 20
• AQUARIUS – from January 21 to February 19
• PISCES – from February 20 to March 20
Perica now wants to count the births in each of the zodiac signs. Write a program that helps Perica count.
Input: The first line of the standard input contains the number N (1 ≤ N ≤ 200), the number of registration numbers that Perica has acquired. In each of the next N lines there is one registration number (13 digits without spaces).
Output: Print 12 integers to standard output, each in a separate line. The first number is the number of people born under the sign of the ram, the second - under the sign of the bull, etc. The last, twelfth number is the number of people born under the sign of fish.
Example 1
Input
5
1504279718463
0412622712918
1903326718649
0710262713307
0104646719372
Output
2
0
0
0
0
0
1
0
1
0
0
1
ARTIMOGRAPHY
The example from the 2nd round of the 2019/20 season qualifications was downloaded from the website dms.rs/informatika-osnovne-skole/
When solving a well-known type of arithmetic rebus, it is necessary to replace the same letters with the same numbers, and different letters with different numbers, so that the exact equality is obtained. For example, for the rebus SNOW + CIRCLE = SPORT, one of the solutions is 1937 + 8627 == 10564. We can make sure that the given equality is indeed correct, but that is not the topic of this task. Here we are interested in the second condition, which is
whether the replacement of letters with numbers was performed correctly. For example, the offered "solution" 4832 + 5962 == 10794 is not correct (although, incidentally, the equality is correct) because the letter S is replaced by the digit 4 in one place and the digit 1 in another. Also, the digit 4 corresponds to two different letters (S and T).
Write a program that checks whether in this type of rebus, the replacement of letters with numbers is performed correctly.
Input:
From the standard input, a string is entered in the first line, which represents the described arithmetic rebus. The string can contain uppercase letters of the English alphabet, spaces, mathematical operation symbols and the equals sign. The total length of the string is no more than 100 and the number of different letters appearing in the string is no more than 10.
In the second line, enter a string representing the proposed solution to the rebus from the first line.
The second string differs from the first only in that each letter is replaced by a number.
Output:
Print "yes" to standard output if the substitution is correct (regardless of whether the equality is correct), and "no" if the substitution is incorrect.
Example 1
Input
SNOW + CIRCLE = SPORTS
2341 + 8751 = 20679
Output
Yes
Example 2
Input
SNOW + CIRCLE = SPORTS
4832 + 5962 = 10794
Output
not
When solving a well-known type of arithmetic rebus, it is necessary to replace the same letters with the same numbers, and different letters with different numbers, so that the exact equality is obtained. For example, for the rebus SNOW + CIRCLE = SPORT, one of the solutions is 1937 + 8627 == 10564. We can make sure that the given equality is indeed correct, but that is not the topic of this task. Here we are interested in the second condition, which is
whether the replacement of letters with numbers was performed correctly. For example, the offered "solution" 4832 + 5962 == 10794 is not correct (although, incidentally, the equality is correct) because the letter S is replaced by the digit 4 in one place and the digit 1 in another. Also, the digit 4 corresponds to two different letters (S and T).
Write a program that checks whether in this type of rebus, the replacement of letters with numbers is performed correctly.
Input:
From the standard input, a string is entered in the first line, which represents the described arithmetic rebus. The string can contain uppercase letters of the English alphabet, spaces, mathematical operation symbols and the equals sign. The total length of the string is no more than 100 and the number of different letters appearing in the string is no more than 10.
In the second line, enter a string representing the proposed solution to the rebus from the first line.
The second string differs from the first only in that each letter is replaced by a number.
Output:
Print "yes" to standard output if the substitution is correct (regardless of whether the equality is correct), and "no" if the substitution is incorrect.
Example 1
Input
SNOW + CIRCLE = SPORTS
2341 + 8751 = 20679
Output
Yes
Example 2
Input
SNOW + CIRCLE = SPORTS
4832 + 5962 = 10794
Output
not
TWO SHELVES
The example from the 2nd round of the 2019/20 season qualifications was downloaded from the website dms.rs/informatika-osnovne-skole/
The store sells two types of shelves whose prices and lengths are known. We want to place the shelves along one wall so that they fill as much of the length of the wall as possible. At the same time, if the same length of the wall can be filled in several ways, we choose the
a smaller variant.
Write a program that determines the largest possible length of wall section that can be filled with shelves and the lowest cost at which it can be done.
Input:
The first line of standard input contains the number z (1 ≤ z ≤ 10^6) which represents
the length of the wall. In the next two lines there are descriptions of the shelves: length (natural number
between 1 and 106) and price (a natural number between 1 and 1000).
Output:
Print the maximum possible length of the part of the wall on the standard output
fill the shelves with the lowest possible price, separated by a single space.
Example
Input
24
3 10
5 8
Output
24 54
The store sells two types of shelves whose prices and lengths are known. We want to place the shelves along one wall so that they fill as much of the length of the wall as possible. At the same time, if the same length of the wall can be filled in several ways, we choose the
a smaller variant.
Write a program that determines the largest possible length of wall section that can be filled with shelves and the lowest cost at which it can be done.
Input:
The first line of standard input contains the number z (1 ≤ z ≤ 10^6) which represents
the length of the wall. In the next two lines there are descriptions of the shelves: length (natural number
between 1 and 106) and price (a natural number between 1 and 1000).
Output:
Print the maximum possible length of the part of the wall on the standard output
fill the shelves with the lowest possible price, separated by a single space.
Example
Input
24
3 10
5 8
Output
24 54
THE GREATEST NUMBER OF THE GIVEN DIGITS
The example from the 3nd round of the 2019/20 season qualifications was downloaded from the website dms.rs/informatika-osnovne-skole/
For the given number, write the largest number written with the same digits.
Input:
From the standard input, the number N (1 ≤ N ≤ 1030) is entered in the first line.
Output:
Print the requested number on the standard output.
Example 1
Input
90123
Output
93210
Example 2
Input
777
Output
777
For the given number, write the largest number written with the same digits.
Input:
From the standard input, the number N (1 ≤ N ≤ 1030) is entered in the first line.
Output:
Print the requested number on the standard output.
Example 1
Input
90123
Output
93210
Example 2
Input
777
Output
777
SOCIAL GAME - RISK
The example from the 3nd round of the 2019/20 season qualifications was downloaded from the website dms.rs/informatika-osnovne-skole/
During the game, the risk attacking and defending players enter battles by rolling dice. Each of them has 3 dice, and based on the current state of the game, it is determined how many of them they can throw. When the dice are rolled, the attacker's strongest die (the one with the highest number) is compared to the defender's strongest die, then second-highest to second-highest, and lowest to lowest. If a player rolled less dice, then the weakest dice of the other player is ignored (the one who rolled more dice has the advantage). When two dice are compared, if the attacker has the strictly stronger die (the die on which the number is strictly higher) the defense loses one point, while otherwise the offense loses one point (thus giving the defender a slight advantage).
Write a program that determines the number of points based on the result of throwing dice
both players lose.
Input:
The first line of the standard input contains the number of dice the attacker rolled (1, 2 or 3),
and the next row contains the numbers (from 1 to 6) on the dice rolled by the attacker. Next
the standard input row contains the defender's number of dice rolled (1, 2 or 3), a
the next row contains the numbers (1 to 6) on the dice rolled by the defender.
Output:
Print the number of points that the attacker loses and the number of points that the attacker loses on the standard output
lost by the defender, separated by one space.
Example 1
Input
3
5 6 3
3
5 3 4
During the game, the risk attacking and defending players enter battles by rolling dice. Each of them has 3 dice, and based on the current state of the game, it is determined how many of them they can throw. When the dice are rolled, the attacker's strongest die (the one with the highest number) is compared to the defender's strongest die, then second-highest to second-highest, and lowest to lowest. If a player rolled less dice, then the weakest dice of the other player is ignored (the one who rolled more dice has the advantage). When two dice are compared, if the attacker has the strictly stronger die (the die on which the number is strictly higher) the defense loses one point, while otherwise the offense loses one point (thus giving the defender a slight advantage).
Write a program that determines the number of points based on the result of throwing dice
both players lose.
Input:
The first line of the standard input contains the number of dice the attacker rolled (1, 2 or 3),
and the next row contains the numbers (from 1 to 6) on the dice rolled by the attacker. Next
the standard input row contains the defender's number of dice rolled (1, 2 or 3), a
the next row contains the numbers (1 to 6) on the dice rolled by the defender.
Output:
Print the number of points that the attacker loses and the number of points that the attacker loses on the standard output
lost by the defender, separated by one space.
Example 1
Input
3
5 6 3
3
5 3 4
ATP WINNER
The example from the 3nd round of the 2019/20 season qualifications was downloaded from the website dms.rs/informatika-osnovne-skole/
During the year, many tennis tournaments are played where tennis players win points. The points are added up and at the end of the year a final list is published where the tennis players are ranked based on the total number of points during that year. Write a program that, based on the results of all tournaments, determines the best tennis player and his points (assume that the winner will have a strictly higher number of points than everyone else).
Input:
The number n is entered from the standard input, and then in the next n lines data about the points won by the tennis player: the last name of the tennis player and then the number of points won.
Output:
Print the name and total number of points of the winner on the standard output.
Example 1
Input
9
Djokovic 1000
Nadal 800
Federer 600
Nadal 1000
Federer 800
Djokovic 600
Djokovic 1000
Tsitsipas 800
Nadal 600
Output
Djokovic 2600
Example 2
Input
6
Zverev 1000
Tsitsipas 800
Medvedev 700
Thiem 1000
Tsitsipas 800
Medvedev 600
Output
Tsitsipas in 1600
During the year, many tennis tournaments are played where tennis players win points. The points are added up and at the end of the year a final list is published where the tennis players are ranked based on the total number of points during that year. Write a program that, based on the results of all tournaments, determines the best tennis player and his points (assume that the winner will have a strictly higher number of points than everyone else).
Input:
The number n is entered from the standard input, and then in the next n lines data about the points won by the tennis player: the last name of the tennis player and then the number of points won.
Output:
Print the name and total number of points of the winner on the standard output.
Example 1
Input
9
Djokovic 1000
Nadal 800
Federer 600
Nadal 1000
Federer 800
Djokovic 600
Djokovic 1000
Tsitsipas 800
Nadal 600
Output
Djokovic 2600
Example 2
Input
6
Zverev 1000
Tsitsipas 800
Medvedev 700
Thiem 1000
Tsitsipas 800
Medvedev 600
Output
Tsitsipas in 1600
Previous
|< Preparation for district competitions |