次の解決策は、最適ではないかもしれませんが、あなたのために動作するかどうかを確認してください。
私はその後、私はお互いを再生する10チームのすべての異なる組み合わせをcomtainsリストを作成し、各ゲーム
public struct Game {
private int TeamA;
private int TeamB;
private bool GamePlayed;
// I am adding this to quickly see what team is playing. I used this for debugging
// purposes to make sure the same team doesn't play another team twice.
public override ToString() {
return TeamA.ToString() + " vs. " + TeamB.ToString();
}
}
を保持するための構造を作成することによって開始します。 45が必要です。
List<Game> AllGamesInSchedule = new List<Game>();
for (int i = 1; i <= 10; i++) {
for (int j = (i + 1); j <= 10; j++) {
AllGamesInSchedule.Add(new Game(i, j));
}
}
// This prints all the different game combinations out to the console to see
// that they are all different.
foreach (Game game in AllGamesInSchedule) {
Console.WriteLine(game.ToString());
}
これで、このリストからゲームを選ぶ方法を作成できます。ゲームを選んだら、GamePlayedフィールドをtrueに変更して、この試合を再度選んではならないことを確認します。または、リストからゲームを削除することもできます。
あなたはガイダンスが必要だと言ったので、ゲームを選ぶ方法を作成しなかったのです。
これが役に立ちます。
私はこのコードでアルゴリズムを見たいと思っています... – ganders