注册 登录
编程论坛 VB6论坛

求从杂乱无章的数列中提取非降序数列段的算法

黝黑蜗壳 发布于 2014-10-09 10:48, 390 次点击
如题。。。 想了几天也没明白
这是我的算法 但是有问题 不知道问题在哪 还望指教
Private Sub Command1_Click()
'Dim counter As Integer, i As Integer, x As Integer
    Open App.Path & "\数据.txt" For Input As #1
        Do While Not EOF(1)
        Line Input #1, temp
        x = x + 1
        Loop
    Close #1
'Dim sj(60000)
i = 1
    Open App.Path & "\数据.txt" For Input As #2
        While Not EOF(2)
        Input #2, sj(i)
        i = i + 1
        Wend
    Close #2

For counter = 1 To x - 1
    'Select Case sj(counter)
        'Case Is <= sj(counter + 1) And Text1.Text <> ""
            'Text1.Text = Text1.Text & vbNewLine & sj(counter)
            'GoTo end_:
        'Case Is <= sj(counter + 1) And Text1.Text = ""
            'Text1.Text = sj(counter)
            'GoTo end_:
        'Case Is >= sj(counter - 1) And sj(counter) <= sj(counter + 1) And Text1.Text <> ""
           ' Text1.Text = Text1.Text & vbNewLine & sj(counter)
            'GoTo end_:
        'Case Is >= sj(counter - 1) And sj(counter) <= sj(counter + 1) And Text1.Text = ""
            'Text1.Text = sj(counter)
            'GoTo end_:
'end_:
    'End Select
    If sj(counter) <= sj(counter + 1) And Text1.Text <> "" Then
        Text1.Text = Text1.Text & vbNewLine & sj(counter)
    ElseIf sj(counter) <= sj(counter + 1) And Text1.Text = "" Then
        Text1.Text = sj(counter)
    ElseIf sj(counter) >= sj(counter - 1) And sj(counter) <= sj(counter + 1) And Text1.Text <> "" Then
        Text1.Text = Text1.Text & vbNewLine & sj(counter)
    ElseIf sj(counter) >= sj(counter - 1) And sj(counter) <= sj(counter + 1) And Text1.Text = "" Then
        Text1.Text = sj(counter)
    End If
Next
End Sub
1 回复
#2
yangfrancis2014-10-10 22:50
首先要有一个dim used(1 to x-1) as boolean
...'全部赋值为false
从第二项开始,只考虑
if sj(counter)>=sj(counter-1) then
   if not used(counter-1) then
           ...'输出第counter-1项
           used(counter-1)=true
   end if
   if not used(counter) then
           ...'输出第counter项
           used(counter)=true
   end if
end if
1