c# - 治具制作

标签 c# algorithm

Forming a tournament table with LINQ (Fixture List) 上的最后一篇文章开始

添加数字列表时,例如

var fixture = ListMatches(new List<string> { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16" });

当我运行代码时,数字 1 始终是第二个。例如

Round 1
9 v 1

Round 2
10 v 1

Round 3
11 v 1

我正在努力弄清楚如何修改代码,以便每个“回合”的数字从“主场”和“客场”交替出现。因此,如果 1 是第二名,那么在下一轮它将是第一名。如果 16 在第 1 轮中排名第一,那么它在第 2 轮中将在客场排名第 2。

Round 1
9 v 1

Round 2
1 v 10

Round 3
11 v 1

最佳答案

这可能是个愚蠢的建议,但您可以切换偶数回合的游戏顺序。

List<List<Tuple<string, string>>> fixture = 
  ListMatches(new List<string> { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16" });

bool switchOrder = false;
foreach (round in fixture)
{
  if (switchOrder)
  {
     foreach (var tuple in round)
     {
         string temp = tuple.Item1;
         tuple.Item1 = tuple.Item2;
         tuple.Item2 = temp;
     }
  }
  switchOrder = !switchOrder
}

关于c# - 治具制作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14025065/

相关文章:

c++ - STL 算法如何独立于 Iterator 类型工作?

c# - 方法重载与可选参数

c# datetimepicker : how do i get the date in the format? 2001/1/1

c# - 使用 Visual Studio 2019 在本地调试 Azure Function

c++ - 分段初筛

algorithm - 学习编程技巧的优先顺序及其他建议

python - 算法中 "combine"函数的最佳方法?

c# - 使网站上的自动完成更具响应性的技术

c# - Mysql 查询替换字符串

c++ - 编程练习的回溯解决方案(安装管道)