文字游戏会为单词中使用的字母奖励积分。英文字母的频率越低,该字母的分数越高。编写一个要求用户输入单词的程序。然后,程序应根据以下规则输出单词的分数:
https://i.stack.imgur.com/Fhyli.jpg
**我已经完成了**
Sub Main()
Dim total As Integer
Dim word As String
total = 0
Console.Write("Word:")
word = Console.ReadLine()
Select Case word
Case = "e"
total = total + 1
Case = "a"
total = total + 2
Case = "r"
total = total + 3
Case = "i"
total = total + 4
Case = "o"
total = total + 5
Case = "t"
total = total + 6
Case = "n"
total = total + 7
Case = "s"
total = total + 8
Case = "l"
total = total + 9
Case = "c"
total = total + 10
Case = "u"
total = total + 11
Case = "d"
total = total + 12
Case = "p"
total = total + 13
Case = "m"
total = total + 14
Case = "h"
total = total + 15
Case "g"
total = total + 16
Case = "b"
total = total + 17
Case = "f"
total = total + 18
Case = "y"
total = total + 19
Case = "w"
total = total + 20
Case = "k"
total = total + 21
Case = "v"
total = total + 22
Case = "x"
total = total + 23
Case = "z"
total = total + 24
Case = "j"
total = total + 25
Case = "q"
total = total + 26
End Select
Console.WriteLine(total)
Console.ReadLine()
但是输出为0,我想知道如何考虑整个单词以及如何考虑1个单词中的多个字母。
答案 0 :(得分:0)
很简单,创建一个字典,其中包含在加载表单时的字母和点。 创建一个返回字母的点值的函数,并在每个循环中循环遍历字符串。 您需要一个文本框,按钮和标签。
Dim WordPoints As New Dictionary(Of String, Integer)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
WordPoints.Add("e", 1)
WordPoints.Add("a", 2)
WordPoints.Add("r", 3)
WordPoints.Add("i", 4)
WordPoints.Add("o", 5)
WordPoints.Add("t", 6)
WordPoints.Add("n", 7)
WordPoints.Add("s", 8)
WordPoints.Add("l", 9)
WordPoints.Add("c", 10)
WordPoints.Add("u", 11)
WordPoints.Add("d", 12)
WordPoints.Add("p", 13)
WordPoints.Add("m", 14)
WordPoints.Add("h", 15)
WordPoints.Add("g", 16)
WordPoints.Add("b", 17)
WordPoints.Add("f", 18)
WordPoints.Add("y", 19)
WordPoints.Add("w", 20)
WordPoints.Add("k", 21)
WordPoints.Add("v", 22)
WordPoints.Add("x", 23)
WordPoints.Add("z", 24)
WordPoints.Add("j", 25)
WordPoints.Add("q", 26)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim TotalPoints As Integer
For Each letter As String In TextBox1.Text.ToLower
TotalPoints += WordPoints(letter)
Next
Label1.Text = TotalPoints.ToString
End Sub
您需要添加的内容是对文本框的更多处理,因此它不接受空格,数字和特殊字符。 并根据需要对其进行自定义。