子題2(9%):請列出文章中使用那些「A」或「a」開頭的單字?
輸入說明:
第1 行表示文章的行數(行數至多10 行,每行最多120 個字),第2 行開始為文章的內容。
輸出說明:
依單字在文章中出現之順序,輸出開頭為「A」或「a」的單字。輸出的單字大小寫需保持與
原文章相同,而每行只輸出1 個單字。若同一單字多次出現在文章中,只有該單字在文章中
首次出現時才被輸出,第2 次或以後出現時均不再輸出。
輸入範例:【檔名:in-1-2.txt】
4
Just ask a Chinese fruit farmer who now has to pay people to pollinate apple trees because there are no
longer enough bees to do the job. And it's not just the number of bees that are rapidly dwindling. As a
direct result of human activity, species are becoming extinct at a rate 1,000 times greater than the natural
average.
輸出範例:【檔名:out-1-2.txt】
ask
a
apple
are
And
As
activity
at
average
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, mycount
Do
Input #1, temp
strr = strr & temp
Loop Until EOF(1)
strr = Replace(strr, ".", "")
strr = Split(strr, " ")
For i = 0 To UBound(strr)
For ii = i + 1 To UBound(strr)
If Mid(strr(i), 1, 1) <> "A" And Mid(strr(i), 1, 1) <> "a" Then strr(i) = ""
If Mid(strr(ii), 1, 1) <> "A" And Mid(strr(ii), 1, 1) <> "a" Then strr(ii) = ""
If strr(i) <> "" And strr(ii) <> "" Then
If strr(i) = strr(ii) Then strr(ii) = ""
End If
Next
Next
For iii = 0 To UBound(strr)
If strr(iii) <> "" Then Print #2, strr(iii)
Next
Close #2
Close #1
End
End Sub
Dim n, g As Integer
回覆刪除Dim b() As String
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: g = 1
For w = 1 To Val(n)
Line Input #1, x
x = Replace(x, ".", "")
x = Replace(x, ",", "")
a = Split(x)
For i = 0 To UBound(a)
ReDim Preserve b(g)
If Left(a(i), 1) = "A" Or Left(a(i), 1) = "a" Then b(g) = a(i): g = g + 1
Next i
Next w
For i = 1 To UBound(b)
For j = i + 1 To UBound(b)
If b(i) = b(j) Then b(j) = ""
Next j
Next i
For i = 1 To UBound(b)
If b(i) <> "" Then Print #2, b(i)
Next i
Close #2
Close #1
End
End Sub