2011年10月19日 星期三

97模擬 Problem 1 (字數統計

  雷迪雅被老師要求寫一份為數2000 字的報告,可是雷迪雅胸無點墨、才疏學淺,常常寫了一整個下午還不到一頁,

  因此他每寫一段時間就開始數自己已經寫了多少個字,可是常常這樣數也是會累的,於是他希望能有一個自動字數統計
程式。

  有了字數統計程式,就可以自動統計好一篇文章總共有幾行、有幾個字、有幾個字元。行被定義為用換行字元隔開的連續字元,字被定義為用空白、TAB 或換行字元所隔開的連續字元,而字元除了一般可見的字元還包括TAB 字元和空白字元(注意不包含換行字元)。
  身為雷迪雅好朋友的你,常常受到他的照顧,正所謂吃人嘴軟,拿人手短,如今雷迪雅遇到了這個難題,請你義不容辭地寫一個程式幫他吧!

輸入說明:
  輸入檔第一行說明有幾組測試資料,第二行開始即為第一筆測試資料,每行不會超過1024個字元,每組測試資料中間用五個連續等號'=' 的一行來作分隔。每組測試資料之中絕不會有五個連續等號'=' 出現。

輸出說明:
  每組測試資料輸出一行,每行有三個數字,分別代表一組測試資料中有幾行,幾個字和幾個字元,每個數字之間請用一個空白隔開。

輸入範例:
2
This is a sample input.
Hello World!!
=====
The speech by Hunyak, translated, is:
"What am I doing here?
They say, the famous Hungarian police,
that I held down my husband and chopped off his head.

But I didn't do it, I am not guilty.
I can't believe that Uncle Sam says I did it.
They say I didit, but really I didn't."


輸出範例:
2 7 36
8 55 270

4 則留言:

  1. 輸入有誤~
    正確應該是這樣


    2
    This is a sample input.
    Hello World!!
    =====
    The speech by Hunyak, translated, is:
    "What am I doing here?
    They say, the famous Hungarian police,
    that I held down my husband and chopped off his head.

    But I didn't do it, I am not guilty.
    I can't believe that Uncle Sam says I did it.
    They say I didit, but really I didn't."

    回覆刪除
  2. 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 i = 1 To N
    Lt = 0
    Pt = 0
    Byt = 0
    Do While Not EOF(1)
    Line Input #1, X
    If X = "=====" Then Exit Do
    Lt = Lt + 1

    If X <> "" Then
    For j = 1 To Len(X)
    If Mid(X, j, 1) = " " Then Pt = Pt + 1
    Byt = Byt + 1
    Next j
    Pt = Pt + 1
    End If

    Loop

    Print #2, Lt & " " & Pt & " " & Byt
    Next i
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  3. Dim a, b, c, s, x 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, t

    Do While Not EOF(1)
    Line Input #1, x

    If x = "=====" Then
    Print #2, a & " " & b & " " & c
    a = 0
    b = 0
    c = 0
    Else
    a = a + 1
    s = Split(x)
    b = b + UBound(s) + 1
    c = c + Len(x)
    End If

    Loop
    Print #2, a & " " & b & " " & c
    Close
    Close
    End
    End Sub

    回覆刪除
  4. Sub main()
    Open App.Path & "\test1.txt" For Input As #1
    Open App.Path & "\result1.txt" For Output As #2
    Input #1, total
    Do Until EOF(1)
    Line Input #1, tmp
    If tmp = "=====" Then
    Print #2, crlf & " " & word & " " & wr
    crlf = 0: word = 0: wr = 0
    Else
    crlf = crlf + 1
    k = Split(tmp, " ")
    word = word + UBound(k) + 1
    wr = wr + Len(tmp)
    End If
    Loop
    Print #2, crlf & " " & word & " " & wr
    End Sub

    回覆刪除