某密碼的破譯步驟如下:
(1)找出文章(以“?!苯Y(jié)束)中所有用英文表示的數(shù)字(均為小寫,數(shù)字范圍1≤n≤20),單詞與數(shù)字對(duì)應(yīng)如下:
單詞 |
one |
two |
three |
four |
five |
six |
seven |
eight |
nine |
ten |
…… |
twenty |
數(shù)字 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
…… |
20 |
(2)將這些數(shù)字平方后除以100取余,得到兩位數(shù)如00,04,21,96。
(3)把這些兩位數(shù)按升序排成一行,組成一個(gè)最小的新數(shù),如果新數(shù)開(kāi)頭為0,就去除。
(4)步驟(3)找出的最小數(shù)即為密碼。
小明按照上述方法,設(shè)計(jì)了一個(gè)解密的VB程序,功能如下:?jiǎn)螕簟敖饷堋卑粹oCommandl,程序依次將文本框Textl中以空格分隔的每個(gè)英文單詞取出,若單詞屬于數(shù)字單詞,則按解密步驟進(jìn)行處理,最后在文本框Text2中輸出解密結(jié)果。程序運(yùn)行效果如圖所示,請(qǐng)回答下列問(wèn)題:
(1)若文章內(nèi)容為“tom bought two apples and five oranges,which cost ten dollars altogether?!保瑒t破譯后的密碼應(yīng)為
425
425
。
(2)請(qǐng)?jiān)跈M線處填入合適的代碼。
Dim a(1To 20)As String
Private Sub Form_Load ( ?。?br />a(1)=“one“:a(2)=“two“
'……將所有數(shù)字單詞按順序存入數(shù)組a中,代碼略
End Sub
Private Sub Command1_Click ( ?。?br />Dim s As String,tmp As String
Dim c as Integer,i As Integer,j As Integer,k As Integer,t As String,ch As As String,code As Long
Dim b(1To 100)As String'b數(shù)組存放數(shù)字單詞處理后得到的兩位數(shù)
s=Text1.Text
c=0:i=1:flag=True:t=““
Do While i<=Len(s)
ch=Mid(s,i,1)
If ch>=“a“And ch<=“z“Then
t=t+ch
flag=False
ElseIf flag=False Then
For j=1To 20
If t=a(j) Then
c=c+1
b(c)=
①
①
End If
Next j
t=““
flag=True
End If
i=i+1
Loop
’將b數(shù)組中的兩位數(shù)按數(shù)值大小進(jìn)行升序排序,代碼略
For i=1To c
t=Val(b(i))
②
②
Next i
Text2.Text=Str(code)
End Sub
Function decode(num As Integer) As String
Dim mo As Integer
mo=num*num Mod 100
If mo=0Then
decode=“00“
ElseIf
③
③
Then
decode=“0“+Trim(Str(mo))
Else
decode=Trim(Str(mo))'Trim為去除字符串兩端空格的函數(shù)
End If
End Function