100求解,不够再开帖!

Qqwwee_Com 2005-07-09 10:05:29
给出一组数字,判断这组数字是否是被分割开的连续的4段?
比如:0,1,2,3 ,5,6,7,11,12,16,17,18 是4段连续数字 0-3 5-7 11-12 16-18

...全文
72 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ccghghgj 2005-07-09
  • 打赏
  • 举报
回复
Dim Strs() As Integer = New Integer() {1, 2, 3, 4, 6, 7, 9, 10, 11, 14, 15, 16, 18, 19, 20}

Dim intCur As Integer '当前数值
Dim IntPrew As Integer
Dim IntRang As Integer '一共找到多少段
Dim intS() As Integer = New Integer() {-1, -1, -1, -1, -1, -1, -1} '保存段的开始数字
Dim intE() As Integer = New Integer() {-1, -1, -1, -1, -1, -1, -1} '保存段的结束数字
For i As Integer = 0 To Strs.Length - 2
intCur = Strs(i)
IntPrew = Strs(i + 1)
If IntPrew - intCur = 1 Then
If intS(IntRang) = -1 Then
intS(IntRang) = intCur
End If
If i = Strs.Length - 2 Then
'如果到了倒数第二数字,最后一个数字就是结束了
intE(IntRang) = IntPrew
End If
Else
intE(IntRang) = intCur '设置当前段的结束
IntRang += 1 '连续的数字段计数器+1
End If
Next
MsgBox(IntRang + 1)

===============================
http://qqwwee.com/csdn.rar
CSDN小助手
ccghghgj 2005-07-09
  • 打赏
  • 举报
回复
久仰久仰!

===============================
http://qqwwee.com/csdn.rar
CSDN小助手
TechnoFantasy 2005-07-09
  • 打赏
  • 举报
回复
to ccghghgj(CSDN论坛助手) :
是的~~~~~~
TechnoFantasy 2005-07-09
  • 打赏
  • 举报
回复
Dim count

count = 1
for i = lbound(a) to ubound(a) - 1
if a(i) <> a(i+1) then
count = count +1
end if
next i
ccghghgj 2005-07-09
  • 打赏
  • 举报
回复
楼上,www.applevb.com是你的么,以前刚开始学习vb的时候经常去

===============================
http://qqwwee.com/csdn.rar
CSDN小助手
TechnoFantasy 2005-07-09
  • 打赏
  • 举报
回复

做一个计数,从第一个值开始递增,如果下一个值等于递增后的值就继续往下。如果不等于则计数加1。最后如果计数是4的话就可以说是连续的。

16,553

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧