0

我在经典 asp 中有一个二维数组,例如
1-5
1-3
2-5

我需要以下格式的数组输出
1-8
2-5

请帮我

4

1 回答 1

2

您需要一个字典来总结由 col1 值分组的 col2 值。如:

  ReDim aIn(2, 1)
  aIn(0, 0) = 1 : aIn(0, 1) = 5
  aIn(1, 0) = 1 : aIn(1, 1) = 3
  aIn(2, 0) = 2 : aIn(2, 1) = 5
  Dim dicX : Set dicX = CreateObject("Scripting.Dictionary")
  Dim i
  For i = LBound(aIn, 1) To UBound(aIn, 1)
      dicX(aIn(i, 0)) = dicX(aIn(i, 0)) + aIn(i, 1)
  Next
  ReDim aOut(dicX.Count - 1, 1)
  For i = LBound(aOut, 1) To UBound(aOut, 1)
      aOut(i, 0) = dicX.Keys()(i)
      aOut(i, 1) = dicX(aOut(i, 0))
  Next
  For i = LBound(aOut, 1) To UBound(aOut, 1)
      WScript.Echo aOut(i, 0), aOut(i, 1)
  Next

输出:

======
1 8
2 5
======
于 2013-01-10T12:53:14.740 回答