- 按键认证大神
- 2699998
- 3587
- 11
- 2173 朵
- 7386 个
- 1021 个
- 91120
- 2014-08-23
|
1#
t
T
发表于 2022-05-13 13:02
|
|只看楼主
题目描述- ' 请将断言插件升级到 v1.1
- Import "SmAssert.dll"
- Function 最长零串(数字列表)
- // 您的代码写在这里
- End Function
- SmAssert.That 最长零串(Array(-1, 0, 1)) ,"=", Array(-1, 0, 1)
- SmAssert.That 最长零串(Array(1, 2, -3, 7, 8, -16)) ,"=", Array(1, 2, -3)
- SmAssert.That 最长零串(Array(25, -35, 12, 6, 92, -115, 17, 2, 2, 2, -7, 2, -9, 16, 2, -11)) ,"=", Array(92, -115, 17, 2, 2, 2)
复制代码 参考题解- ' 请将断言插件升级到 v1.1
- Import "SmAssert.dll"
- VBSBegin
- '【作者】:神梦无痕
- '【QQ】:1042207232
- '【Q群】:584781753
-
- ' 数组求和
- Function Sum(List, StartIndex, EndIndex)
- Dim Result, i
- Result = 0
- If StartIndex >= LBound(List) And EndIndex <= UBound(List) Then
- For i = StartIndex To EndIndex
- Result = Result + List(i)
- Next
- End If
- Sum = Result
- End Function
-
- ' 数组切片
- Function Slice(List, StartIndex, EndIndex)
- Dim Result, i
- ReDim Result(EndIndex-StartIndex)
- If StartIndex >= LBound(List) And EndIndex <= UBound(List) Then
- For i = StartIndex To EndIndex
- Result(i-StartIndex) = List(i)
- Next
- End If
- Slice = Result
- End Function
- VBSEnd
- Function 最长零串(数字列表)
-
- '【作者】:神梦无痕
- '【QQ】:1042207232
- '【Q群】:584781753
-
- Dim 零和列表
- Dim i, j
-
- 零和列表 = Array()
- For i = 0 To UBound(数字列表)
- For j = i + 1 To UBound(数字列表)
- If Sum(数字列表, i, j) = 0 And (j - i) > UBound(零和列表) Then
- 零和列表 = Slice(数字列表, i, j)
- End If
- Next
- Next
- 最长零串 = 零和列表
- End Function
- SmAssert.That 最长零串(Array(-1, 0, 1)) ,"=", Array(-1, 0, 1)
- SmAssert.That 最长零串(Array(1, 2, -3, 7, 8, -16)) ,"=", Array(1, 2, -3)
- SmAssert.That 最长零串(Array(25, -35, 12, 6, 92, -115, 17, 2, 2, 2, -7, 2, -9, 16, 2, -11)) ,"=", Array(92, -115, 17, 2, 2, 2)
复制代码 插件下载【插件】神梦断言插件 SmAssert.dll,帮助开发者发现业务逻辑错误
|