jz5 #2665(2007/08/30 03:50 GMT) [ VB.net ] Rating0/0=0.00
要素数2~0のIntegerの配列を返します。 仲間はずれなしの場合 要素数1でxsの1つの値が、 仲間はずれありの場合 要素数2で仲間、仲間はずれの順で値が入っています。 その他の場合要素数0で返ります。 呼び出し例 Dim xs() As Integer = {1, 2, 1, 1} For Each x In Classify(xs) Console.Write(x & ", ") Next 結果 1, 2,
1 2 3 4 5 6 7 8 9 10
Function Classify(ByVal xs() As Integer) As Integer() Dim seq = From x In xs Group By x Into Count() Order By Count If seq.Count = 1 Then Return New Integer() {seq.First.x} ElseIf seq.Count = 2 AndAlso seq.First.Count = 1 Then Return New Integer() {seq(1).x, seq(0).x} End If Return New Integer() {} End Function
Rating0/0=0.00-0+
[ reply ]
jz5
#2665()
[
VB.net
]
Rating0/0=0.00
要素数2~0のIntegerの配列を返します。 仲間はずれなしの場合 要素数1でxsの1つの値が、 仲間はずれありの場合 要素数2で仲間、仲間はずれの順で値が入っています。 その他の場合要素数0で返ります。 呼び出し例 Dim xs() As Integer = {1, 2, 1, 1} For Each x In Classify(xs) Console.Write(x & ", ") Next 結果 1, 2,Rating0/0=0.00-0+
[ reply ]