/
SofiMut
/
teamSort
Обзор
Документация
Войти
/
SofiMut
/
teamSort
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
47 строк
1 KB
Софья Степанова
upload files
21 авг 2025, 06:05
21 авг 2025, 06:05
b41b4cd
Код
Авторство
О чём код?
import java.io.IOException; import java.util.Arrays; public class Main { public static void main(String[] args) throws IOException { int[][] teams = { {45, 31, 24, 22, 20, 17, 14, 13, 12, 10}, {31, 18, 15, 12, 10, 8, 6, 4, 2, 1}, {51, 30, 10, 9, 8, 7, 6, 5, 2, 1} }; int[] nationalTeam = mergeAll(teams); System.out.println(Arrays.toString(nationalTeam)); // [51, 45, 31, 31, 30, 24, 22, 20, 18, 17] } public static int[] mergeAll(int[][] teams) { int[] team = teams[0]; for (int i = 1; i < teams.length; i++) { team = merge(team, teams[i]); } return team; } public static int[] merge(int[] teamA, int[] teamB) { int[] teamC = new int[10]; int a = 0; int b = 0; int c = 0; while (c < 10) { if (a < teamA.length && (b >= teamB.length || teamA[a] >= teamB[b])) { teamC[c++] = teamA[a++]; } else { teamC[c++] = teamB[b++]; } } return teamC; } }