2012年11月20日 星期二

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


Problem 1:文章的字母統計及單字的分離
選手請由輸入檔讀入一篇英文文章(文章內容包括「大、小寫英文」、「空白」及「標點符號」, 沒有任何「全型」字母或符號),並作以下的統計:
子題19%): 若不區別英文字母大小寫,請統計26 個英文字母A~Z在文章中出現的次數?
(只統計英文字母,其他如空白、標點符號等皆不統計。)

輸入說明:
行表示文章的行數(行數至多10 行,每行最多120 個字),第行開始為文章的內容。
輸出說明:
行分別列出字母ABCD及其統計次數,第行列出字母FGHI及其統計次數,每行輸出個字母及統計,以此類推;但最後一行只列出字母及其統計次數。英文字母以「大寫」輸出,每個字母及其統計次數印在組小括號中,並由逗號分隔。

輸入範例:【檔名:in-1-1.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-1.txt
(A, 27) (B, 6) (C, 7) (D, 6) (E, 38)
(F, 4) (G, 6) (H, 11) (I, 14) (J, 3)
(K, 1) (L, 9) (M, 5) (N, 16) (O, 16)
(P, 8) (Q, 0) (R, 18) (S, 15) (T, 28)
(U, 9) (V, 2) (W, 3) (X, 1) (Y, 3)
(Z, 0)

1 則留言:

  1. Dim strr 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
    Do
    Input #1, temp
    strr = strr & temp
    Loop Until EOF(1)
    For i = 65 To 90
    ori = Len(strr)
    strr = Replace(strr, Chr(i), "")
    strr = Replace(strr, Chr(i + 32), "")
    Print #2, "(" & Chr(i) & "," & ori - Len(strr) & ")" & "";
    If (i + 1 - 65) Mod 5 = 0 And i <> 65 Then Print #2,
    ori = Len(strr)
    Next
    Close #2
    Close #1
    End
    End Sub

    回覆刪除