Private Sub Command1 Click()
Label2 Caption = trans(Val(Text1. Text),Val(Text2. Text))
End Sub
Function trans(n As Integer, k As Integer) As String
If n< >0 Then
r = n Mod k
trans = trans(n\ k, k)+Str(r)
Else trans = 0
End If
End function
程序运行时,在文本框Text1和Text2中分别输入11和3,则Label2中的输出结果是( )
Dim s As String, ch As String
Dim i As Integer, t As Integer
s = Text1.Text : t = 0
For i = 1 To Len(s)
ch = Mid(s, i, 1)
If ch <> "," Then t = t * 2 + Val(ch)
Text2.Text = Text2.Text + Str(t)
Next i
执行该程序,当文本框Text1中输入了“11,10”时,文本框text2中输出的是( )
Private Sub Comand1_Click( )
Dim s As String, c As String
Dim t As Integer, I As Integer
Dim a(1 To 26)As Integer
s=Text1.Text
For i=1 to 26
a(i)=0
Next i
i=1
Do While i<=Len(s)
c=Mid(s, i, 1)
If ① Then
t=Asc(c)-96
Else
t=Asc(c)-64
End If
If a(t)=0 Then
a(t)=1
Else
②
End If
i=i+1
Loop
Label1.Caption=s
End Sub
① ②
求解思路:在七个区域①、②、③、④、⑤、⑥、⑦上枚举七个数字1、2、3、4、5、6、7的所有排列来进行验证。程序运行界面如图c所示。
图c
请回答下列问题:
Dim a(1 To 7) As Integer 'a(1)~a(7)依次存储区域①~⑦的值
Private Sub Command1_Click()
Dim i As Integer, n As Integer
Dim y1 As Integer, y2 As Integer, y3 As Integer
For i = 1 To 7
a(i) = i
Next i
n = 0
Do While True
For i = 7 To 2 Step -1
If a(i) = 8 Then
a(i) = 1
End If
Next i
If a(1) = 8 Then Exit Do
If check() Then
y1 = a(1) + a(2) + a(3) + a(4)
y2 = a(2) + a(4) + a(5) + a(6)
y3 = a(3) + a(4) + a(6) + a(7)
If y1 = y2 And Then
n = n + 1
'在列表List1中,按格式输出a数组元素的值,代码略
End If
End If
a(7) = a(7) + 1
Loop
Label1.Caption = "解法共计" & Str(n) & "种。"
End Sub
Function check() As Boolean
Dim i As Integer, n As Integer, f(1 To 8) As Integer
For i = 1 To 8
f(i) = 0
Next i
For i = 1 To 7
Next i
n = 0
For i = 1 To 7
n = n + f(i)
Next i
If n = 7 Then check = True Else check = False
End Function
for s in "grandfather":
if s=='d'or s==' h':
continue
print(s,end='')

图1
图2
