题型:综合题 题类:常考题 难易度:普通
浙江省高中信息技术 子序列问题练习
Dim a(1 To 100) As Integer
Dim sum(0 To 100) As Integer ’sum(i)存储 a(1)+a(2)+…+a(i)的值
Dim n As Integer, s As Integer
Private Sub Form_Load()
‘读取整数序列依次存储在数组a中
‘读取整数序列长度存储在变量n中
‘本过程代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer, ans As String
Dim Min As Integer ‘存储符合条件的最小长度
Dim iMin As Integer ‘存储符合条件子序列的起始位置
s=val(Text2.text)
For i = 0 To n
sum(i) = 0
Next i
For i = 2 To n
sum(i) = a(i) + sum(i-1)
Next i
Min = n
iMin = 1
For i = 1 To n
j=i
Do WhileAnd j<= n
j = j + 1
Loop
If j <= n And j - i + 1 < Min Then
Min = j - i + 1
iMin = i
End If
Next i
ans =“”
For i = iMin To
ans = ans + Str(a(i))
Next i
Label1.Caption = “符合条件的子序列为” + ans
End Sub
试题篮