程序代码如下:
Private Sub Form Click()
Dim ji As Integer ‘鸡
Dim tu As Integer ‘兔
Dim tui As Integer ‘腿数
Dim tou As Integer ‘头数
For ji=
For tu=1 to 25
tui= ‘计算腿的数量
tou= ji+tu ‘计算头的数量
IFThem
Print ji, tu
End If
Next tu
Next ji
End sub
For i=1 To 10 Step 4
s = s+i
Next i
该程序段运行后,语句s=s+i执行的次数为( )
For i=1 to 5
s=s+1
next i
s=0
For i=1 To 3
s=s+i
Next i
<循环变量> <遍历结构>:
<语句块>
program=["Java","Python","Visual Basic"]
for i in program:
print (i,len(i))
for i in range(1, 10, 3):
print(i, end=",")
| m= 1 m = m+ 5 n = 5 + m Print n ,m |
| a = 2 b = 3 print a > b |
| a=10 b=20 If a>b then Print a, b Else Print b, a End if |
| For k=15 to 1 step -5 Print k; next |
For i in range(①):
Print("抗击疫情,广州加油!")
将字符串(均为大写字符)s依次转换为相对应的数值(字符A~Z对应数值1~26);
·转换后的数值以K个数据为一段,将n个待处理的数据依次分割成若干段(最后一段不足部分用0来补充);
每一段中K个数据与K*K转置矩阵进行乘法运算;
将乘法运算得到的每一个结果值除以26求余数,依次转换成相应字符(数值1~26对应字符A~Z),最后按原始字符串长度输出。
乘法运算规则如下:
第i个元素c(i)=第j个元素a(j)*转置矩阵第j行第i个元素b(t)的乘积之和(其中j=1,2…K)
例如:字符串s=PYTHON,区块大小K=4,的转置过程如下:


Private Sub Command1_Click()
Dim a(1 To 100)As Integer '存储字符串,长度不超过100个字符
Dim b(1 To 100)As Integer '存储转置矩阵,长度不超过10*10
Dim c(1 To 100)As Long
Dim s As String, tmp As String
Dim k As Integer, t As Integer, i As Integer, j As Integer
Dim n As Integer, m As Integer, lens As Integer
s=Text1. Text '在Text1中输入原始字符串
k=Val(Text 2.Text) '在Text2中输入区块大小K
Randomize
For i=1 To k^2
b(i)=Int(Rnd*9)+1
tmp=tmp+Str(b(i))
If i Mod k=0 Then
List 2. AddItem tmp
tmp=""
End If
Next i
lens=Len(s):n=lens
For i=1 To n
tmp=Mid(s,i,1)
List1. AddItem Str(a(i))
Next i
Do While n Mod k<>0
n=n+1
a(n)=0
List1. AddItem Str(a(n))
Loop
For i=1 To n
m=(i-1) Mod k+1
t=1
For j=
c(i)=a(j) * b((m-1) * k+t)+c(i)
t=t+1
Next j
Next i
For i=1 To n
List3. AddItem Str(c(i))
Next i
s=″″
For i=1 To lens
s=s+Chr(t+64)}
Next i
Text 3.Text=s '在Text 3中输出转置后的字符串
End Sub
①
②
③
④
b=1
Do while (b<40)
b=b*(b+1)
Loop
Print b
Dim m, n, k As Integer
m = 6
n = 1
For k = 1 To m Step 2
n = n * k
Next k
Print "n ="; n
程序运行后,n的值是:
