Dim a(1 To 100) As Integer
Dim n As integer
Private Sub Form_Load()
‘本过程从数据库中读取n个IP地址区间数据,并依次存入数组a(1)、…、a(2*n)中对能通过过滤的IP区间按区间起始端点升序排序
代码略
End Sub
Private Sub Cmd1_Click()
Dim ip As Integer,L As Integer, R As Integer
Dim i As Integer,pos As Integer, f As Boolean
ip=Val (Text1. Text)
L=a(1):R=a(2):i=3:pos=1 ‘合并重叠区间
Do While i<=2*n-1
If Then
If a(i+1)>R Then R=a(i+1)
Else
a(2*pos-1)=L
a(2*pos)=R
pos=pos+1
L = a(i)
R=a(i+1)
End If
Loop
a(2*pos-1)=L:a(2*pos)=R ‘依次输出排序合并后的区间数据,代码略
If Then ‘判断请求的IP地址
Labe14. Caption= “IP需过滤”
Else
i=1:f=False
Do While i<=pos And Not f
If Then
i =i+1
else
Labe14. Caption=“IP不需过滤”
f=True
End If
Loop
If f=False Then Labe14. Caption=“IP需过滤"
End if
End sub
inp= input("请输入a、b: ") #1
a=float (inp.split( )[0])
b=float (inp.split( )[1]) #2
if a>b: #3
print(a)
else #4
print(b)
①明文字符与对应密钥的ASCII码转化为二进制后求异或(对应位相同时结果为0,对应位不同时结果为 1,如二进制1001与二进制1100的异或值为0101),并将异或结果转换为十进制p;
②如果处在奇数位,则将明文字符循环后移p个位置,否则将明文前移p个位置。移动过程中保持大小写不变。
最后把所得到的字符连接起来就是密文。
例如,密钥是“abc”,明文“d”的加密过程是:字符“d”的ASCII码表示为二进制是1100100,密钥“a”的ASCII码表示为二进制是1100001,两数进行异或结果是:0000101,转化为十进制为5,因为是第1个位置,所以把明文后移5个位置,则密文是“i”。
该加密过程使用VB来实现。具体功能设计如下:在Text1中输入明文,Text2中输入密钥,单击“开始加密”按钮Command1后将密文显示在Text3中,界面设计如图所示。
请回答以下问题:
Private Sub Command1_Click()
Dim s As String, sn As String
Dim i As Integer, t As Integer, u As Integer
Dim p As Integer, g As Integer
sn = ""
For i = 1 To Len(Text1.Text)
t = Asc(Mid(Text1.Text, i, 1))
If t >= Asc("a") Then
g = Asc("a")
Else
g = Asc("A")
End If
u = Asc(Mid(Text2.Text, (i - 1) Mod Len(Text2.Text) + 1, 1))
p =
t = t - g
If i Mod 2 = 1 Then
t = (t + p) Mod 26
Else
t =
End If
sn = sn + Chr(t + g)
Next i
Text3.Text = sn
End Sub
Function txor(x As Integer, y As Integer) As Integer 'x、y求异或并返回十进制
Dim a As Integer, b As Integer, r As Integer, i As Integer
a = x: b = y
r = 1
For i = 1 To 7
If a Mod 2 <> b Mod 2 Then
a = a \ 2
b = b \ 2
r = r * 2
Next i
End Function
Dim d(1 to 5)as integer, i as integer
Dim flag as Boolean, j as integer
‘给数组元素d(1)至d(5)赋初值为1,代码略
Randomize
For i=1 to 5
J = 1: flag = True
d(i) = int(Rnd*9)
Do while j< =i-1 and flag = True
d(i) = int(Rnd*5+1)
If d(i) = d(j) then i=i-1: flag = False
j = j+1
Loop
Next i
运行程序后,数组中的数据值可能是( )
a=3; b=1; c=2
if a>b:
a,b=b,a
if b>c:
b,c=c,b
if a>b:
a,b=b,a
print(a,b,c)
其输出结果为( )
Private Sub CmdTJ_Click()
Dim count(25) As Integer
Dim ch, ch2 As String
Dim m As Integer
ch = Text1.Text
For k = 1 To Len(ch)
n = Asc(ch2)-Asc(“a”)
If n >= 0 And n <= 25 Then
count(n) = count(n) + 1
List1.AddItem "字母" + ch2 + "出现" + Str(count(n)) + "次"
End If
Next k
m = count(0)
For k = 1 To 25
If Then m = count(k)
Next k
Label1.Caption = "字母最高出现" + Str(m) + "次"
End Sub
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
① ②
st = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
s=””
For i= 1To 4
t = Int(Rnd*8)*2+11
If t\10=2Then
t=t+1
Else
t=t-1
End If
s=s+Mid(st,t,1)
Next i
List1.AddItem s
执行该程序段后,列表框List1中可能显示的内容是( )
第一排正中间安排1人;第二排正中间安排3人;第三排正中间安排5人……,如此循环,直至班级人数不足以站满一排后结束编排。
三角队形外围一圈的同学对服装有特殊要求,需要进行标记(中间的同学用“●”标记,外围的同学用“▲”标记)
编写VB程序,实现队形编排功能:在文本框Text l中输入班级人数,单击“展示队形”按钮Command1后,将班级学生队形显示在列表框List 1中。例如,当班级学生数为54的时候,程序运行界面如图所示。
Private Sub Command 1_Click( )
Dim i As Integer,j As Integer
Dim cnt As Integer,nAs Integer,tmp As Integer
Dim kw As String,zw As String,c As String
List 1.Clear
cnt=Val(Text 1.Text)
n=0:tmp= 1
Do While ‘计算三角队形的行数
cnt=cnt-tmp
tmp=tmp+ 2
n=n+1
Loop
For i=1 T on
kw="":zw=""
For j=i T on-1
kw=kw+" "
Next j
If i=n The nc="▲" Else c="●"
For j= 1 To 2*(i-1)-1
zw=zw+c
Next j
IfThen
ZW="▲"
Else
zw="▲"+zw+"▲"
End If
List 1.Add Item
Next i
End Sub
If x And y Then x=0
Else x=1后x的结果为( )。
Text1.text="相同":j=1
Do while j<=len(s2)
If mid(s1, 1, 1)=mid(s2, j, 1) then
s1=mid(s1, 2, len(s1)-1)
s2=mid(s2, 1, j-1)+mid(s2, j+1, len(s2)-j)
Else
If
Text1.text="不相同"
End if
End if
Loop
方框中的代码由以下三部分组成:
①j=j+1 ②j=1 ③j=len(s2)+1
则(1)、(2)、(3)中代码顺序正确的是( )
Private Sub Command1_Click()
s = "Tokyo_Olympic_Games"
ans = ""
For i = 1 To Len(s)
c = Mid(s, i, 1)
If (2020 \ 10 ^ 2 - i) <= Len(s) Mod 10 \ 3 Then
If c >= "a" And c <= "z" Then c = Chr(Asc(c) - Asc("a") + Asc("A"))
End If
ans = ans + c
Next i
Label1.Caption = ans
End Sub
执行上述程序段后,标签Labele1中输出的内容为( )
a = [10, 5, 2, 11, 7,6]
c=0
i = 0
while i < len(a):
if a[i] % 2 == 0:
c -= a[i]
else:
c += a[i]
i =i + 1
print(c)
程序执行后,输出的结果是
X=val(inputbox(“shuru”))
IF X>=0 THEN
PRINT SQR(X)
ELSE
PRINT X
END IF
运行时键盘输入-4
s = 0: i = 1
Do While i <= 10
If i Mod 3 = 0 Then a(i) = a(i) + 1 Else a(i) = i
List1.AddItem Str(a(i))
i = i + 1
Loop
i = 10
Do While i >= 1
If a(i) = 1 Then s = s + 1
i = i - 1
Loop
该程序段运行后,变量s值是( )
BMI指数 |
<18.522.9 |
18.5~23~ |
25~24.9 |
29.9 |
≥30 |
≥40.0 |
结果 |
偏瘦 |
正常 |
偏胖 |
肥胖 |
重度肥胖 |
极重度肥胖 |
程序运行时,在文本框Text1中输入体重,在文本框Text2中输入身高,单击”测试”按钮Command1,在标签Label4中显示对应的结果。程序运行界面如下图所示。
实现上述功能的VB程序如下,请回答下列问题:
Private Sub Command1_Click()
Dim h As Single, w As Single, ans As Single, s As String
w = Val(Text1.Text)
h = Val(Text2.Text)
①
If ans< 18.5 Then
s = “偏瘦”
ElseIf ans< 22.9 Then
s = “正常”
ElseIf ans<= 24.9 Then
s = “偏胖”
ElseIf ans<= 29.9 Then
s = “肥胖”
ElseIf ans< 40 Then
s = “重度肥胖”
②
s = “极重度肥胖”
End If
Label4.Caption = s
End Sub
① ②
有四个嫌疑人甲乙丙丁涉嫌偷盗,其中一人是小偷。甲说“不是我”,乙说“是丙”,丙说“是丁”,丁说“丙在冤枉我”。若他们中只有一人说了假话,请编程判断谁是小偷。(注:在Python运算中,True的值为1,Fa1se的值为0)
运行输出结果是
①海伦公式是利用三角形的三条边的边长直接求三鱼形面积的公式,表达式为
其中P是三角形的周长的一半。
⑵请填空完善该程序,输入三条边长,判断能否构成三角形。如果能构成三角形就计算该三角形的面积并输出,否则提示不能构成三角形。
⑶编写完成后原名保存并关闭应软件。
import math
a=float(input("请输入第一条边长:"))
b=float(input("请输入第二条边长:"))
c=float(input("请输入第三条边长:"))
if(a+b>c)and(a+c>b)and():
p
s=math.sqrt(p*(p-a)*(p-b)*(p-c))
print(a,b,c,"能构成三角形!","三角形的面积为:",)
:
print(a,b,c,"不能构成三角形!")