题库 高中信息

题干

诗词爱好者小奇发现一些诗句中的叠字(有至少二个重叠的字)非常优美,如“庭院深深深几许”……,小奇希望用VB编写程序,寻找诗句中的叠字。程序运行界面如下:

(1)每次点击“运行”按钮,自动清空列表框List1的内容,可在过程“Command1_Click”中加入List1.Clear,其中“Clear”是 (单选,填字母:A.对象名/B.方法/C.属性/D.事件)
(2)实现上述功能的VB程序如下,请在划线处填入合适的代码。
Private Sub Command1_Click()
Dim i As Integer, n As Integer, flag As Boolean, txt As String
txt = text1.Text
n = Len(txt)
c = 1
For i = 1 To n - 1
If Mid(txt, i, 1) =   ①    Then
flag = True
c = c + 1
Else
flag = False
End If
If ② Then
list1.AddItem Mid(txt, i - c + 1, c)
c = 1
End If
Next i
If c > 1 Then list1.AddItem Mid(txt, i - c + 1, c)
End Sub
(3)若去掉加框代码,输入的诗句为“贫恨苦吟穷寞寞,乱愁牵断梦沉沉”(不含引号),则启动程序,单击“运行”按钮后,列表中    (单选,填字母)
A.输出:寞寞沉沉 B. 输出:沉沉 C. 输出:寞寞 D. 无输出
上一题 下一题 0.99难度 填空题 更新时间:2019-05-15 10:47:01

答案(点此获取答案解析)

同类题2

挤牛奶问题:如有三个农民每天清晨5点起床,然后去牛棚分别给3头牛挤奶。第一个农民在300时刻(从5点开始计时,秒为单位)给他的牛挤奶,一直到1000时刻(总共挤了700个时刻),第二个农民在700时刻开始,在1200时刻结束(总共挤了500个时刻)。第三个农民在1500时刻开始2100时刻结束(总共挤了600个时刻)。期间最长挤奶的连续时间为900秒(从300时刻到1200时刻),而最长的无人挤奶的连续时间为300时刻(因第二个农民在1200时刻已结束,而第三个农民从1500时刻才开始,中间有300时刻没有人在挤牛奶)。相应时刻如下图所示:

下面提供的程序是,从N个农民(1<N<=5000)挤N头牛的工作时间列表,计算出最长有人在挤牛奶的时间段与最长的无人挤牛奶的时间段。
下图为两组不同数据程序运行后界面;

请在划线处填入相应的代码,使程序功能完善。
Dim a(1 To 100) As Integer '存放农民挤牛奶开始时刻
Dim b(1 To 100) As Integer '存放农民挤牛奶结束时刻
Dim n As Integer '存放农民人数
Private Sub Form_Load()
‘获取农民的人数与各个农民开始挤牛奶与结束挤牛奶的时间,并在list1中输出
‘相应的代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim t As Integer, ymax As Integer, nmax As Integer
Dim btime As Integer, etime As Integer, flag As Boolean
flag = True: i = 1
Do While i <= ________And flag
flag = False
For j = 1 To n - i
If a(j) > a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
t = b(j): b(j) = b(j + 1): b(j + 1) = t
flag = True
End If
Next j
i = i + 1
Loop
btime = a(1): etime = b(1)
ymax = etime - btime: nmax = 0
For i = 2 To n
If _______________________________Then
etime = b(i)
If etime - btime > ymax Then ymax = etime - btime
ElseIf etime < a(i) Then
If a(i) - etime > nmax Then nmax = a(i) - etime
btime = a(i): etime = b(i)
End If
Next i
Label2.Caption = "最长挤牛奶时间为:" + Str(ymax) + " 时刻"
Label3.Caption = "最长无人挤牛奶时间为:" + Str(nmax) + " 时刻"
End Sub