s = "Python2.0": ans = "" For i = 1 To Len(s)
ch = Mid(s, i, 1)
If ch >= "A" And ch <= "Z" Then
ch = Chr(Asc("A") + (Asc(ch) - Asc("A") + 23) Mod 26)
ElseIf ch >= "a" And ch <= "z" Then
ch = Chr(Asc("a") + (Asc(ch) - Asc("a") + 3) Mod 26)
End If
ans = ch + ans Next i Label1.Caption = ans
执行该程序段后,标签Label1上显示的内容为( )。
n = 8
For i = 1 To n
a(i) = Int(Rnd() * 10) + 1 Next i
For i = 1 To n \ 2
If a(i) < a(i + 1) Then p = i: q = i + 1 Else p = i + 1: q = i For j = i + 2 To n - i + 1
If a(j) < a(p) Then q = p: p = j
ElseIf a(j) < a(q) Then q = j
End If Next j
If i <> p Then t = a(p): a(p) = a(i): a(i) = t
If i = q Then q = p
If n - i + 1 <> q Then t = a(q): a(q) = a(n - i + 1): a(n - i + 1) = t
Next i
执行该程序段后,a(1)~a(8)各元素可能的值为( )。
实现上述功能的部分代码如下:
key = Val(Text2.Text) i = 1: j = 10
Do While i <= j m = (i + j) 2
if i = m + 1
Then
Else
j = m - 1 End If
Loop
Label1.Caption = "大于等于" + Str(key) + "的成绩有" + Str(num) + "个"
上述程序段2个方框处的代码分别为( )。
图 a
请回答下列问题:
图 b
图 c
图 d
图 a
请回答下列问题:
编号 |
1 |
2 |
3 |
4 |
5 |
生产时间 |
4 |
7 |
5 |
5 |
9 |
商品价值 |
10 |
16 |
12 |
10 |
15 |
若生产时间为20,则可生产编号为1、2、5的商品,总价值为10+16+15=41。
编写一个VB程序,实现如下功能:在文本框Text1中依次输入各商品(数量小于等于10件)的生产时间和价值(整数用逗号分隔并以逗号结尾),在文本框Text2中输入总加工时间(至少可以生产一件商品),单击“确定”按钮Command1后,在列表框List1中显示最大的总价值和生产的商品编号。程序运行界面如图所示。
Private Sub Command1_Click()
Dim n As Integer, i As Integer, j As Integer, k As Integer, c As Integer, p As Integer
Dim temp As xue Integer, sum1 As Integer, sum2 As Integer, max As Integer, ans As Integer Dim s As ke String, wang ch As String, v(1 To 10) As Integer, t(1 To 10) As Integer
s = Text1.Text
n = Val(Text2.Text)
c = 00: k = 0
For i = 1 To
ch = Mid(s, i, 1)
If ch <> "," Then k = k + 1
Else
c = c + 1
temp = Val(Mid(s, i - k, k)) k = 0
If c Mod 2 = 1 Then t(p) = temp Else v(p) = temp
End If
Next i
c = c \ 2
For i = 1 To 2 ^ c - 1 k = i: j = c
Do While k > 0
IfThen sum1 = sum1 + v(j): sum2 = sum2 + t(j): j = j - 1
k = k \ 2 Loop
If max < max = sum1: ans = i sum1 = 0: sum2 = 0
Next i
List1.AddItem "最大价值是:" + Str(max)
List1.AddItem "生产商品如下:" ‘输出生产的商品,代码略
End Sub
班级 |
1班 |
2班 |
3班 |
4班 |
5班 |
6班 |
7班 |
8班 |
9班 |
10班 |
人数 |
50 |
45 |
50 |
51 |
49 |
55 |
50 |
48 |
52 |
50 |
Const n = 500 '总学生数
Const m = 10 '总班级数Dim score(1 To n) As Integer
Dim stu_name(1 To n) As Integer Dim class(1 To n) As Integer Dim temp1(1 To n) As Integer Dim temp2(1 To n) As Integer Dim temp3(1 To n) As Integer Function adj(s As String)
'本函数在字符串s 前添加若干空格,实现右对齐,代码略
End Function
Private Sub Form_Load()
'本过程读取学生姓名、班级和成绩数据分别存储在数组stu_name,class 和score 中,
'并在 List1 中显示,代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer, t1 As Integer, t2 As String
Dim c(0 To m + 1) As Integer
For i = 0 To m
c(i) = 0
Next i
For i = 1 To n
c(k) = c(k) + 1
Next i
For i = 1 To m
c(i) = c(i) + c(i - 1)
Next i
For i = n To 1 Step -1
k = class(i)
temp1(c(k)) = score(i)
temp2(c(k)) = stu_name(i)
temp3(c(k)) = class(i)
Next i '处理完毕 c(i+1)表示第 i 个班级的最后一个学生的存储位置
c(m + 1) = n
For k = 1 To m '对每一个班级学生成绩进行排序For i = c(k) + 1 To c(k + 1) - 1
For j = c(k + 1) To i + 1 Step -1
If Then
t1 = temp1(j): temp1(j) = temp1(j - 1): temp1(j - 1) = t1
t2 = temp2(j): temp2(j) = temp2(j - 1): temp2(j - 1) = t2
t1 = temp3(j): temp3(j) = temp3(j - 1): temp3(j - 1) = t1
End If
Next j
Next i
Next k
For i = 1 To n
score(i) = temp1(i): stu_name(i) = temp2(i): class(i) = temp3(i)
List2.AddItem adj(Str(stu_name(i))) & adj(Str(class(i))) & adj(Str(score(i)))
Next i
End Sub