/**
* Makes a schedule for teams, if there are an even number of them.
* Generate teams.size()-1 rounds, rotating the teams between each one.
* Team 0 should be at home in the first round, then it should alternate home and away.
* See the project description for some examples.
* You may assume that teams.size() >= 2 and teams.size() is even.
*/
我尝试使用数组列表
int rounds = teams.size()/2;
for(int i=0; i<rounds;i++) {
if (i<1){
int home_team = teams.get(i);
int away_team = teams.get(i+1);
System.out.println("Team "+ home_team+" vs "+away_team);
}
else{
fixtures.add(1);
}
}
第一轮的结构如下。
然后我们轮换团队;我们将最后一支队伍上移到列表的第二位。
T1, T6, T2, T3, T4, T5
您可以看到T6已移至T1之后的位置。名单上的第一支队伍永远不会受到轮换的影响。