试题

试题 试卷

logo

题型:填空题 题类: 难易度:容易

新疆伊犁哈萨克自治州霍城县2023-2024学年高一上学期信息技术10月月考试卷

在IDLE编辑器中执行下列程序语句,输出结果为_。

a=356

b=365

a=b

print(a)

举一反三
小明编写统计字符串中出现最多的字母和数字的程序。程序运行如下:在文本框Text1中输入一个仅包含字母和数字的字符串。单击按钮Command1后,在标签Label1上显示出现最多的数字字符,在标签Label2上显示出现最多的字母字符(字母不区分大小写,例如字母G和g统计在一起)。程序运行界面如图所示。

实现上述功能的VB程序如下,请在划线处填入合适的代码。

Private Sub Command1_Click()

Dim a(1 To 10) As Integer    ‘存储0~9每个数字出现的次数

Dim b(1 To 26) As Integer    ‘存储a~z每个字母出现的次数

Dim zf As String, x As String, p As Integer

Dim maxa As Integer, maxb As Integer

{#blank#}1{#/blank#}

For i = 1 To Len(zf)

 x = Mid(zf, i, 1)

 If pd(x) = 1 Then

  p = Asc(x) - Asc(“0”) + 1

  a(p) = a(p) + 1

  {#blank#}2{#/blank#}

  p = Asc(x) - Asc(“A”) + 1

  b(p) = b(p) + 1

 Else

  p = Asc(x) - Asc(“a”) + 1

  b(p) = b(p) + 1

 End If

Next i

k = a(1):maxa = 1

For i = 2 To 10

 If a(i) > k Then k = a(i):maxa = i

Next i

k = b(1) :maxb = 1

For i = 2 To 26

 If{#blank#}3{#/blank#}Then k = b(i) :maxb = i

Next i

Label1.Caption =“出现最多的数字是” + Chr(maxa+ Asc(“0”)-1)

Label2.Caption = “出现最多的字母是” + Chr(maxb + Asc(“A”)-1)

End Sub

Function pd(ch As String) As Integer ’函数用于判断每个字符类型

 If ch >= “0” And ch <= “9” Then pd = 2

 If ch >= “A” And ch <= “Z” Then pd = 2

 If ch >= “a” And ch <= “z” Then pd = 3

End Function

返回首页

试题篮