对于谁不知道冠军联赛是由32支球队组成,分为8组,每组包含4支球队,他们在主场和客场之间进行比赛,然后每组的前两支球队进入季后赛比赛< / p>
注意:我考虑过分组,并且我想出的最好的东西是2D阵列,如果您还有其他解决方案,请告诉我
我有五个ArrayList,其中包含来自不同联赛的100支球队,分别是联赛,laLiga,ligue1,serieA,德甲
现在如何由不同的团队随机填充每个组,请注意,一个组不应有两个相同联赛的团队,而且每个组应包含不同级别的团队
我想制作一个临时列表,以便我可以轻松地将它们混合在一起,以便稍后将它们传递给2D阵列
List<Team> temp = new ArrayList<>();
Random r = new Random();
int num = 0;
internal:
while (true) {
num = r.nextInt(7);
if (!temp.contains(premireLeague.getTeam(num))) {
temp.add(premireLeague.getTeam(num));
break internal;
}
}
internal:
while (true) {
num = r.nextInt(7);
if (!temp.contains(laLiga.getTeam(num))) {
temp.add(laLiga.getTeam(num));
break internal;
}
}
for (int i = 0; i < 6; i++) {
internal:
while (true) {
num = r.nextInt(7);
if (!temp.contains(premireLeague.getTeam(num))) {
temp.add(premireLeague.getTeam(num));
break internal;
}
}
internal:
while (true) {
num = r.nextInt(7);
if (!temp.contains(laLiga.getTeam(num))) {
temp.add(laLiga.getTeam(num));
break internal;
}
}
internal:
while (true) {
num = r.nextInt(6);
if (!temp.contains(ligue1.getTeam(num))) {
temp.add(ligue1.getTeam(num));
break internal;
}
} internal:
while (true) {
num = r.nextInt(6);
if (!temp.contains(serieA.getTeam(num))) {
temp.add(serieA.getTeam(num));
break internal;
}
} internal:
while (true) {
num = r.nextInt(6);
if (!temp.contains(bundesliga.getTeam(num))) {
temp.add(bundesliga.getTeam(num));
break internal;
}
}
}
Team[][] groupsTable = new Team[8][4];
int tempnum = 0;
for (int i = 0; i < 8; i++) {
for (int z = 0; z < 4; z++) {
groupsTable[i][z] = temp.get(tempnum);
tempnum++;
}
}
我想出了什么,但我认为这是愚蠢而不明智的方式