中文题目: http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/chs/aevent7.mspx
英文解题: http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/apssol07.mspx
替补比较简单, 就是C(6, 2)的组合题目. 唯一的要求在于, 不能简单的顺序输出结果, 要求随机输出. 只要是随机即可, 我利用hash对象, 加上随机数. 然后利用Sort进行排序. 事实证明, 我这次搞复杂了, 我可以Sort @{e= {$r.Next()}}直接就可以随机排序了, 这是 PowerShell Guy想到的...由衷佩服他对PowerShell的熟练. 我的解题代码:
$r
=
[Random] (Get
-
Date)
.
Millisecond
$team = " ABCDEF "
$( for ( $i = 0 ; $i - lt $team . Length ; $i ++ )
{
for ( $j = $i + 1 ; $j - lt $team . Length ; $j ++ )
{
$h = New - Object - TypeName Collections . HashTable
$h . c = $team [ $i ] + " vs. " + $team [ $j ]
$h . r = $r . Next ()
$h
}
}) | Sort - Object - property @{e = { $_ . r}} | % { $_ . c }
$team = " ABCDEF "
$( for ( $i = 0 ; $i - lt $team . Length ; $i ++ )
{
for ( $j = $i + 1 ; $j - lt $team . Length ; $j ++ )
{
$h = New - Object - TypeName Collections . HashTable
$h . c = $team [ $i ] + " vs. " + $team [ $j ]
$h . r = $r . Next ()
$h
}
}) | Sort - Object - property @{e = { $_ . r}} | % { $_ . c }