Problem1:找出文章中使用的英文單字字數(14%)
現在網際網路盛行,網路使用者可以利用搜尋引擎找出特定的網路資訊。在搜尋技術中,
關鍵字搜尋是最常見的方法。建立關鍵字有很多種不同的方法,其中一種方法是找出使用的
單字來當作關鍵字。本題就是要請你寫一個程式,可以在一段英文文章中,找出使用的英文
單字字數。
輸入說明:
第一行是要建立關鍵字的英文文章篇數,第二行開始為英文文章的內容。每篇文章之間,
以一行空白作為區隔。在建立關鍵字時,我們簡化一些文法上的規則,每個英文單字與英文
單字之間,扣除標點符號之後,以空白作為區別,稱之為一個單字,大小寫視為相同。使用
到的標點符號則包括下列三個:『,』,『.』,以及『:』。
輸出說明:
對輸入的每篇文章,分別以一行輸出使用的英文字字數。
輸入範例:
2
He works hard from morning till night. He is a hard worker.
I once heard him speaking in English. He is a very good speaker of English.
輸出範例:
10
14
Dim s
回覆刪除Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, t
For i = 1 To t
Line Input #1, n
n = LCase(n)
s = Split(n)
Call A1
Next
Close
Close
End
End Sub
Sub A1()
Dim ch As Boolean
ans = 0
List1.Clear
For i = 0 To UBound(s)
ch = True
If Left(s(i), 1) < "a" Or Left(s(i), 1) > "z" Then s(i) = Right(s(i), Len(s(i)) - 1)
If Right(s(i), 1) < "a" Or Right(s(i), 1) > "z" Then s(i) = Left(s(i), Len(s(i)) - 1)
For j = 0 To List1.ListCount - 1
If s(i) = List1.List(j) Then ch = False
Next
If ch = True Then List1.AddItem s(i): ans = ans + 1
Next
Print #2, ans
End Sub
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, N
For ii = 1 To N
Line Input #1, x
x = LCase(x)
List1.Clear: List2.Clear
Temp = ""
For i = 1 To Len(x)
A = Mid(x, i, 1)
If A >= "a" And A <= "z" Then
Temp = Temp & A
Else
If RE(Temp) = fasle Then List1.AddItem Temp: Temp = ""
End If
Next i
Print #2, List1.ListCount
Next ii
Close #2
Close #1
End
End Sub
Function RE(B)
P = False
For i = 0 To List1.ListCount - 1
If List1.List(i) = B Then P = True
Next i
If B = "" Then P = True
RE = P
End Function
3
回覆刪除AA aa AAA aaa, BBB bbb: cC Cc.
Good morning, Miss Lin. I am sorry. You have the wrong number.
Those flowers are beautiful. She can play baseball and basketball. Those flowers are beautiful. She can play baseball and basketball.
這是評分用的測試檔,每句話中間都有空一行...試試看吧
解答:
4
12
10