輸入說明:
第一行是要建立關鍵字的英文文章篇數,第二行開始為英文文章的內容。每篇文章之間,以一行空白作為區隔。在建立關鍵字時,我們簡化一些文法上的規則,每個英文單字與英文單字之間,扣除標點符號之後,以空白作為區別,稱之為一個單字,大小寫視為相同。使用到的標點符號則包括下列三個:『,』,『.』,以及『:』。
輸出說明:
對輸入的每篇文章,分別以一行輸出使用的英文字字數。
輸入範例:
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 times, ans As Integer
回覆刪除Dim strr As String
Dim repeat As Boolean
Private Sub Form_Load()
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
ans = 0
Input #1, times
For ai = 1 To times
Line Input #1, strr
strr = Replace(strr, ",", "")
strr = Replace(strr, ".", "")
strr = Replace(strr, ":", "")
strr = LCase(strr)
strrr = Split(strr, " ")
For i = 0 To UBound(strrr)
For ii = i + 1 To UBound(strrr)
If strrr(i) = strrr(ii) Then repeat = True
Next
If repeat = False Then ans = ans + 1
repeat = False
Next
Print #2, ans
ans = 0
Next
Close #2
Close #1
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, x
For i = 1 To x
Line Input #1, y
y = Replace(y, ",", "")
y = Replace(y, ".", "")
y = Split(y)
a = 0
For j = 0 To UBound(y)
a = a + 1
For k = j + 1 To UBound(y)
If y(j) = y(k) Then
Sum = Sum + 1
End If
Next
' Print #2, y(j)
Next
Print #2, a - Sum
Sum = 0
Next
Close #2
Close #1
End
End Sub
作者已經移除這則留言。
回覆刪除Dim t As Boolean
回覆刪除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, X
For i = 1 To X
Line Input #1, y
y = Replace(y, ",", "")
y = Replace(y, ".", "")
y = Replace(y, ":", "")
s = Split(y, " ")
ans = 0
For j = 0 To UBound(s)
t = False
For k = j + 1 To UBound(s)
If s(j) = s(k) Then t = True: Exit For
Next
If t = False Then ans = ans + 1
Next
Print #2, ans
Next
Close
Close
End
End Sub
輸入說明最後一段的最後一點前面有個空格,會讓程式錯誤...,這個是我的程式錯誤嗎?