Plus
Pin


Problem description Progress
ID 29474. bubble sort
Темы: Quadratic sorts   

It is required to sort the array in non-descending order using the "bubble" method.
 
Input
The first line contains one natural number N not exceeding 1000 – array size. The second line contains N numbers – array elements (integers not exceeding 1000 in modulo).
 
Output
Output the resulting array.
 
Examples
# Input Output
1
5
5 4 3 2 1
1 2 3 4 5

ID 23590. Using sort
Темы: Quadratic sorts   

The heights of all students in the class are known. Determine the height of a student who, when plotted by height, in ascending order, would be ranked 10th from the tallest student.

The built-in sort cannot be used.
 

Input
The first line contains a natural number N - the number of students in the class (11 <= N <= 35).
In the second line, N integers are entered - the growth of students.

Imprint
It is necessary to display the height value of the student who would be ranked 10th in height in descending order, counting from the tallest student.
 
Example
# Input Output
1 12
148 144 154 145 155 130 157 136 152 130 177 166
136

ID 22009. Olympiad results
Темы: Quadratic sorts   

N Olympiad participants received unique numbers from 1 to N. As a result of solving problems at the Olympiad, each participant received a certain amount points (an integer from 0 to 600).  It is known who scored how many points. It is required to list the participants of the Olympiad in non-increasing order of their points.
 
Input
First enter the number N (\(1<=N<=100\)) - the number of participants in the Olympiad. Next enter N numbers - the number of points scored by the participants (1st number - these are the points scored by participant number 1, 2nd number - participant number 2, etc.).
 
Output
Output N numbers - the numbers of the participants in non-increasing order of their points (participants with the same number of points can be displayed in any order).
 
Example
# Input Output
1
5
100 312 0 312 500
5 2 4 1 3

ID 29476. Mission Serenity
Темы: Quadratic sorts   

The crew of the Serenity interplanetary ship of the class Firefly delivers cargo to various planets of the star system. The ship has a secret cargo hold consisting of N × M cells. Each cell of the cargo compartment has a maximum volume that it can accommodate. It is impossible to fit into the cell a load with a volume greater than the maximum volume of the cell. Only exactly one load can be placed in one cell. 
 
   Serenity Captain Malcolm Reynolds thinks through cargo placement into cells. Help him determine the maximum amount of cargo the captain can deliver.
 
Input
The first line contains numbers N and M (\(1 \leq N, M \leq 40\) ). Each of the following N lines contains M numbers indicating the maximum volume of the corresponding cell. The (N+2)th line contains the number K (\(1 \leq K \leq 2000\)) – the amount of cargo. The (N+3)-th line contains K numbers, the i-th of which is – volume ith cargo. All volumes – natural numbers not exceeding 109.

Imprint
It is required to display one number – the maximum possible amount of cargo that can be delivered.
 
Example
# Input Output
1
3 2
5 10
7 5
5 5
6
9 5 3 5 12 10
4

ID 33474. Обувной магазин
Темы: Quadratic sorts   

В обувном магазине продается обувь разного размера. Известно, что одну пару обуви можно надеть на другую, если она хотя бы на три размера больше. В магазин пришел покупатель. Требуется определить, какое наибольшее количество пар обуви сможет предложить ему продавец так, чтобы он смог надеть их все одновременно.

Входные данные
Сначала вводится размер ноги покупателя (обувь меньшего размера он надеть не сможет), затем количество пар обуви в магазине и размер каждой пары. Размер — натуральное число, не превосходящее 100, количество пар обуви в магазине не превосходит 1000.

Выходные данные
Выведите единственное число — максимальное количество пар обуви.
 

Ввод Вывод
60
2
60 63
2
26 
5
30 35 40 41 42
3

ID 38115. Delivery of containers
Темы: Quadratic sorts   

Malcolm Reynolds has been asked to deliver empty containers to the outermost planet in the star system. There is only one free cell of Х size left on the ship, in which containers can be placed. The captain decided to stack several containers inside each other. All containers are similar in size. A container with a smaller volume fits freely into a container with a volume of 3 conventional units more. What is the maximum number of containers that Captain Reynolds can deliver?

Input
In the first line, a natural  number X is entered - the volume of a free cell (a larger load will not fit in a cell). The second line contains the number of containers. In the third line - the volume of each container. All volumes are natural numbers not exceeding 100, the number of containers does not exceed 1000.

Imprint
Print one number — the maximum number of containers that Malcolm Reynolds can deliver.
 

Examples
# Input Output
1 60
2
60 63
1
2 26 
5
26 24 22 21 18
3

ID 45240. Sorting by number squares
Темы: Quadratic sorts   

Given an array of integers. Return a non-decreasing sorted array of squares of the original numbers.

Input
The program receives as input in the first line a natural number n - the size of the array. The second line contains n integers a- array elements (1 <= n <= 103- 104 <= ai <= 104).

Imprint
Output the resulting array.
 
 

Examples
# Input Output
1 5
-1 -4 3 0 10
0 1 9 16 100
2 3
3 -1 1
1 1 9

ID 45241. Sort by sum of digits
Темы: Quadratic sorts    2D arrays   

Given an array of integers. Sort the array by non-increasing sum of digits of each number. If the sum of the digits of two numbers is equal, the numbers must follow in descending order.

Input
The program receives as input in the first line a natural number n - the size of the array. The second line contains n integers a- array elements (1 <= n <= 1031  ;<= ai <= 104).

Imprint
Output the resulting array.
 
 

Examples
# Input Output
1 4
1 43 ​​12 10
43 12 10 1

ID 45242. Greatest Product of Three Numbers - Search by Sorting
Темы: Quadratic sorts   

Given an integer  N<=103 and N integers. you need to find three numbers whose product is maximal.

Print the three required numbers in non-increasing order.

Input
The first line is an integer 3 <= N <= 103 - number of elements in the list.
The second line contains N integers  list elements that do not exceed 30000 in absolute value.

Imprint
Print the answer to the problem.
 

Examples
# Input Output
1 9
3 5 1 7 9 0 9 -3 10
10 9 9
2 3
-5 -30000 -12
-5 -12 -30000

ID 33207. Сортировка по цифрам числа 2
Темы: One-Dimensional Arrays    Quadratic sorts   

Дано N трехзначных чисел (1<=N<=1000). Необходимо вывести их в порядке увеличения первой цифры в числе. Если первые цифры одинаковы, то вывести их в порядке возрастания.

Нельзя использовать встроенную сортировку

Пример
Входные данные

9
639 265 915 993 436 202 573 906 490 

Выходные данные
202 265 436 490 573 639 906 915 993

ID 33205. Пятый самый легкий
Темы: One-Dimensional Arrays    Quadratic sorts   

Известны массы в килограммах N предметов (6<=N<=100). Определить массу предмета, являющегося "пятым из самых легких предметов".

Нельзя использовать встроенную сортировку

Пример
Входные данные

6
170 150 162 148 175 181 

Выходные данные
175

ID 33203. (Зл17.11) Средние в шеренге
Темы: One-Dimensional Arrays    Quadratic sorts   

Известен рост N человек (N-четное, 2<=N<=100). Определить рост тех двоих людей, которые бы оказались в середине шеренги в случае построения ее по ранжиру (по убыванию роста).

Нельзя использовать встроенную сортировку

Пример
Входные данные

6
170 150 162 148 175 181 

Выходные данные
170 162

 

ID 33202. Использование сортировки 2
Темы: One-Dimensional Arrays    Quadratic sorts   

В каждом из двух классов учатся по N человек (10<=N<=30). Известны средний балл каждого ученика каждого класса, подсчитанные по ряду предметов (все значения целые). Определить, в каком классе у "третьего из самых успевающих учеников" средняя оценка больше. Вывести цифру "1" - для первого класса, "2" - для второго
Если оценки равны, вывести эту оценку

Нельзя использовать встроенную сортировку
 
Примеры:
входные данные
10
3 4 4 3 3 3 2 5 4 5 
4 5 2 2 4 4 5 2 3 5 
выходные данные
2

ID 33206. Сортировка по цифрам числа 1
Темы: One-Dimensional Arrays    Quadratic sorts   

Дано N двузначных чисел (1<=N<=1000). Необходимо вывести их в порядке увеличения первой цифры. Если первые цифры одинаковы, то вывести их в порядке следования в исходном массиве

Нельзя использовать встроенную сортировку

Пример
Входные данные

6
75 15 62 48 70 81 

Выходные данные
15 48 62 75 70 81 

ID 45717. Side diagonal sort
Темы: 2D arrays    Quadratic sorts   

Write a program that rearranges the side-diagonal elements of a square matrix in descending order, starting from the upper right corner. The remaining elements of the matrix should remain in place.
 

Input

The first line contains a single number N the size of a square matrix ( 1 <= N <= 100 ). The following N lines contain matrix rows, each – by N natural numbers separated by spaces. 
 

Output

The program should output the resulting matrix, in which the elements of the main diagonal are arranged in ascending order.
 

Examples
# Input Output
1
5
12 4 8 13 13 
1 12 1 4 15 
2 3 5 2 3 
6 5 13 12 14 
14 9 15 4 12 
12 4 8 13 14 
1 12 1 13 15 
2 3 5 2 3 
6 5 13 12 14 
4 9 15 4 12
 

ID 45719. Sorting a two-dimensional array
Темы: 2D arrays    Quadratic sorts   

Write a program that sorts a two-dimensional array of integers. In this case, the smallest number should be in the first element of the first line, and the largest in the last element of the last line.


Input

The first line contains space-separated dimensions of a two-dimensional array: the number of rows N and the number of columns M ( 1 <=  N , M <= 100 ). The following N lines contain the strings of a two-dimensional array, each – by M natural numbers separated by spaces. 
 

Output

The program should output a sorted two-dimensional array.
 

Examples
# Input Output
1
5 6
13 5 1 8 4 14 5 
5 13 10 9 3 7 7 
3 3 9 6 3 7 5 
10 8 11 2 1 1 13 
1 12 13 15 9 11 4 
1 1 1 1 2 3 3 
3 3 4 4 5 5 5 
5 6 7 7 7 8 8 
9 9 9 10 10 11 11 
12 13 13 13 13 14 15