Const n = 6
Dim a(1 To n) As Integer, f(1 To 10) As Boolean
Dim tmp As Integer, i As Integer, j As Integer, t As Integer
′f数组各元素的初值置为False,代码略
For i = 1 To
t = Int(1+Rnd * 10)
If Not f(t) Then
a(i) = t : f(t) = True
For j =
If a(j) < a(j-1) Then
tmp = a(j): a(j) = a(j-1): a(j-1) = tmp
End If
Next j
Else
End If
Next i
上述程序段3个方框处的表达式分别为( )
m=5
sum=0
while m<10:
sum=sum+m
m=m+1
print(sum)
程序运行后输出的结果为:( )
x=0
while(x!=4): #当x=!4时,执行循环
print('1. 添加订单')
print('2. 发货')
print('3. 查看订单列表')
print('4. 退出')
x=int(input("输入你的选择:")) #输入选择项
if ① :
y=input("输入订单编号:") #输入订单编号
② #在列表listque中添加订单号
elif x==2:
③ #如果订单列表为空
print("订单列表为空")
else:
print("发货单号:"+listque.pop(0))
elif x==3:
print("等待发货:",listque) #查询列表listque中的订单号
print()
input("运行完毕,请按回车键退出...")
① ② ③
i=1
s=1
while ① :
s=s*i
i+=2
print(s)
当输出结果为105时,则①处应填入( )
for i in range(1,5):
n=n*i
print(n)
程序运行后,其输出结果为
| 数组元素 | 数组元素的含义 |
| tj(1) | 存储查找到第1个大于da的零件数 |
| tj(2) | 存储生产了tj(1)个零件的工人数量 |
| … | |
| tj(2*i-1) | 存储查找到第i个大于da的零件数 |
| tj(2*i) | 存储生产了tj(i)个零件的工人数量 |
| … |
例如:tj(1)=1948,tj(2)=12。这对数据的含义为:共有12个工人生产了1948个零件。
实现以上功能的VB程序如下,请回答下列问题:
Private Sub Command1_Click( )
Dim bf(1 To 1000)As Integer
Dim maxn, d, k, sa As Integer
Dim I, j, flag As Integer
da=Val(Text1.Text):maxn=0:k=1
For j=1 To n
If xs(j)>=da Then maxn=maxn+1
bf(maxn)=xs(j)
Next j
For i=1 To maxn
flag=0
For j=1 To i-1
If bf(i)=bf(j) Then flag=1
Next j
If flag=0 Then
①
d=1
For j=i+1 To maxn
If bf(i)=bf(j) Then ②
Next j
tj(2*k)=d
k=k+1
End If
Next i
k=k-1
For j=1 To ③
List1. Addltem Str(tj(j))+" "+Str(tj(j+1))
Next j
End Sub
以上程序段运行时,为了实现上述功能,画线处应填入的代码分别为:①;②;③。
实现上述功能的VB程序如下,但加框处代码有误,请改正。
Private Sub Command1_Click( )
Dim s As String,result As String,pos As String
Dim count As Integer,i As Integer
i=1:count=0
result="":pos=""
Do While i<=Len(Text1.Text)
s=Mid(Text1.Text,i,Len(Text2.Text))
If s=Text2.Text Then
result=result+Text3.Text
count=count+1
pos=
‘①
i=i+Len(Text2.Text)
Else
‘②
i=i+1
End If
Loop
Text4.Text=result
Text5.Text=Str(count)
Text6.Text=pos
End Sub
以上程序段运行时,为了实现上述功能,加框处代码应改正为:①;②。
string-input("输入字符串:")
c=1
p=1
while p <= len(string)-1:
if ①
c+= 1
else:
s += str(c)+string[p-1]
②
p+=1
print("压缩后数据为:" ,s)
① ②
|
错误结果 |
修改代码并说明原因 |
|
输入字符串:RRRRRGGBBBBBB 压缩后数据为: 5R2G |
如字符串“ABDAC”与字符串“AABCD”可以归为同一类,与“AABBC”不可以归为同一类。图图编写了一VB程序,功能如下:在文本框Text1中输入字符串s1,在文本框Text2中输入字符串s2,单击“判断”按钮Command1,在标签Label1中显示是否可以归为同一类的结果。部分运行界面如图所示。
请回答下列问题:
Private Sub Command1_Click()
Dim a(1 To 100) As Boolean
Dim i As Integer, j As Integer
Dim flag As Boolean
s1 = Text1.Text
s2 = Text2.Text
flag = True
For i = 1 To Len(s2)
Next i
If Len(s1) <> Len(s2) Then
flag = False
Else
For i = 1 To Len(s1)
c =
j = 1
Do While j <= Len(s2)
If
Then
a(j) = False
Exit Do
End If
Loop
If j = Len(s2) + 1 Then flag = False
Next i
End If
If flag Then
Label1.Caption = "可以归为同一类"
Else
Label1.Caption = "不可归为同一类"
End If
End Sub
S=0
For i=1 To 14
x=2*i-1
If x Mod 3 =0 Then s=s+1
Next i
For A=1 To 200 Step 4
S=S+A:
Next A
Print S
1)初始时,建立一个空字典,把26个小写字母加入字典中。26个小写英文字母编码为1-26,字母“a”的编码为1,字母“b”的编码为2,其它字母的编码依次增加。
2)从字符串第一个位置开始扫描,若遇到空格(空格用“*”表示),则得到一个单词,截取该单词并存入变量中。
3)若该单词在字典中,则取出该单词在字典中的编码值;否则,依次取出该单词中各字母在字典中的编码值,(编码值之间用一个空格分隔),同时产生该单词的编码(编码为字典中的最大编码值加1),加入字典中。
4)继续扫描字符串,截取单词,并按照步骤(3)的方法进行处理,直至整个字符串编码完毕。字符串“abab”LZW编码过程如图所示。
Dim pos As Integer, a(1 To 100)As String
Private Sub Form_Load( )
'将字母“a”至“z”依次存入数组元素a(1)到a(26)
End Sub
Function judge(ss As String) As Integer '判断字典中是否有ss这个单词
Dim i As Integer judge = 0
For i = 27 To pos
If a(i) =Then judge = i
Exit For
End If
Next i
End Function
Private Sub Command1_Click( )
Dim s As String, i As Integer, j As Integer, k As Integer, ch As String, word As String, result As String, Dim id As Integer, idletter As Integer
s = Text1.Text pos = 26: i = 1
Do While i <= Len(s)
j = i
Do While Mid(s, j, 1) <> " " j = j + 1
If j > Len(s) Then Exit Do
Loop
word = Mid(s, i, j - i)
If Len(word) = 1 Then '单个字母的单词
result = result + Str(Asc(word) -Asc("a") + 1)
Else
id = judge(word)
If id = 0 Then '新的单词
For k = 1 To Len(word) '依次处理该单词中的各个字母编码
ch = Mid(word, k, 1)
Next k
pos = pos + 1 '对该单词编码
a(pos) = word
Else '词典中存在该单词
result = result + Str(id) End If
End If
If j < Len(s) Then result = result + " *"
Loop
Text2.Text = result
End Sub
Private Sub Command1_Click()
Dim s As String, s1 As String, s2 As String
Dim c As Integer, k As Integer, i As Integer, flag As Boolean
flag = False
s = Text1.Text
For c = 1 To Len(s)
If Then Exit For 'Exit for退出循环
Next c
s1 = Mid(s, 1, c - 1)
s2 = Mid(s, c + 1,len(s)-c)
k =
For i = 1 To k - 1
If Val(Mid(s1, 1, i)) + Val(Mid(s1, i + 1,c-i-1)) = Val(s2) Then
List1.AddItem Mid(s, 1, i) + "+" + Mid(s, i + 1,len(s)-i)
End If
Next i
If Not flag Then List1.AddItem "等式始终无法成立!"
End Sub
s=1
i=1
while i<=5:
s=s*i
i=i+1
print(s)
x=int(input("Enter a number: "))
s=
fori in range(1,x+1):
if ==0:
s=
print(s)
ma=a[0];mb=a[0];pa=0;pb=0
for i in range(1,10):
if ma < a[i]:ma = a[i];pa=i
if mb > a[i]:mb = a[i];pb=i
下列关于该程序段功能描述正确的是( )
Dim xm(1 to 1000) as string '存储学生姓名
Dim cj(1 to 1000) as integer '存储学生成绩
Private Sub Form_Load() '该处具体代码省略
'从数据库读取两批学生数据第1批学生的人数rs1,按成绩从高到低的顺序将成绩存入cj(1)、cj(2)…cj(rs1)中,姓名存入xm(1)、xm(2)…xm(rs1)中,第2批人数rs2,按成绩从高到低的顺序将成绩存入cj(rs1+1)、cj(rs1+2)…cj(rs1+rs2)中,姓名存入xm(rs1+1)、xm(rs1+2)…xm(rs1+rs2)中
End Sub
Private Sub Command1_Click()
i=1
j=rs1+1
'以下程序开始按成绩高低逐个输出,每次输出前后两段中,尚未处理的学生中成绩最高的n=1 '①
Do While i<=rs1 And j<=rs1+rs2 '两段都有未输出的情况,输出两段中最大值
n=n+1
If cj(i)>=cj(j) Then
k=i:i=i+1
Else
k=j: j=j+1
End If
List1.AddItem(″第″+Str(n)+″名″+xm(k)+″成绩:″+Str(cj(k)))
Loop
Do While i<=rs1 '剩下第一段还有未输出的,逐个输出
n=n+1
List1.AddItem(″第″+Str(n)+″名″+xm(i)+″成绩:″+Str(cj(i)))
i=i+1
Loop
Do While j<=rs2 '②若第二段还有未输出的,逐个输出
n=n+1
List1.AddItem(″第″+Str(n)+″名″+xm(j)+″成绩:″+Str(cj(j)))
j=j+1
Loop
End Sub
① ②
n=int(input(“n=”))
s=0
for i in range(2, n):
if n%i==0:
s=
if :
print(n,“是素数”)
else:
print(n,“不是素数”)
n =357859604
Do While n>0
c=n Mod 10
If c>5 Then c=5
count (c) = count(c) + 1
n=n\10
Loop
数组元素count (0)到count (9)的初始值均为0,执行该程序段后,则count (5)的值为( )