2012年8月17日 星期五

文章的字母統計及單字的分離(99模擬) -2

子題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

1 則留言:

  1. Private Sub Form_Load()
    Me.Hide
    Dim c As Boolean
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, n
    For i = 1 To n
    Line Input #1, x
    y = LCase(x)
    x = Replace(x, ",", " ")
    x = Replace(x, ".", " ")

    For j = 1 To Len(x)
    If Mid(y, j, 1) < "a" Or Mid(y, j, 1) > "z" Or Mid(y, j, 1) < "0" Or Mid(y, j, 1) > "9" Then x = Replace(x, a, " ")
    Next

    b = Split(x, " ")
    For j = 0 To UBound(b)
    If Mid(b(j), 1, 1) = "A" Or Mid(b(j), 1, 1) = "a" Then
    c = True
    For j1 = 0 To List1.ListCount
    If Mid(b(j), 1, 1) = " " Then c = False: Exit For
    If b(j) = List1.List(j1) Then c = False: Exit For
    Next
    If c = True Then List1.AddItem b(j)
    End If
    Next
    Next
    For j = 0 To List1.ListCount
    Print #2, List1.List(j)
    Next
    Close
    Close
    End
    End Sub

    回覆刪除