재귀는 필요하지 않습니다. 다음은 반복적 인 접근법입니다.
void Main() {
var teams = CreateTeams().ToArray();
int games = teams.Min(t => t.Games.Count);
var ordered = teams.OrderBy(team => 0);
for (int i = games - 1; i >= 0; i--) {
var captured = i; // the value of i will change, so use this capturing variable,
ordered = ordered.ThenByDescending(team => team.Games[captured].Points);
}
ordered = ordered.ThenBy(team => team.Name);
foreach (var team in ordered) {
Console.WriteLine("{0} {1}", team.Name, string.Join(", ", team.Games.Select(game => game.Points)));
}
}
IEnumerable<Team> CreateTeams() {
yield return (new Team("War Donkeys", 1, 2, 3));
yield return (new Team("Fighting Beavers", 2, 2, 3));
yield return (new Team("Angry Potatoes", 2, 1, 3));
yield return (new Team("Wispy Waterfalls", 3, 2, 1));
yield return (new Team("Frisky Felines", 1, 2, 3));
}
class Team {
public string Name { get; set; }
public IList<Game> Games { get; set; }
public Team(string name, params int[] points) {
this.Name = name;
this.Games = points.Select(p => new Game { Points = p }).ToArray();
}
}
class Game {
public int Points { get; set; }
}
출력
Fighting Beavers 2, 2, 3
Frisky Felines 1, 2, 3
War Donkeys 1, 2, 3
Angry Potatoes 2, 1, 3
Wispy Waterfalls 3, 2, 1
는 일치의 최대 개수가된다? 한 팀이 다른 팀보다 더 많은 게임을한다면 어떻게해야합니까? – recursive
당신이 그것을 이해하지 못했다고해도, 당신이 시도한 것을 보여주십시오. – ethorn10
원본 게시물을 편집했습니다 – DAVEWASLIN