2012年11月20日 星期二

找出文章中使用的中文字數

題意同這題 :     找出文章中使用的英文單字字數


輸入說明:
第一行是文章篇數,第二行開始為文章的內容。
每篇文章之間,以一行空白作為區隔。
※中文字不包含標點符號
輸出說明:
對輸入的每篇文章,分別以一行輸出使用的字數。







輸入範例:
2
今天天氣很好


嘩啦啦啦啦啦啦啦啦~!!!!!下大雨了!!!!




輸出範例:
5
6

3 則留言:

  1. 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, strr
    If strr <> "" Then
    Do
    For i = 1 To Len(strr)
    If Asc(Mid(strr, i, 1)) < 0 Then strr = Replace(strr, Mid(strr, i, 1), ""): ans = ans + 1: Exit For
    If Asc(Mid(strr, i, 1)) > 0 Then strr = Replace(strr, Mid(strr, i, 1), ""): Exit For
    Next
    Loop Until Len(strr) = 0
    Print #2, ans
    ans = 0
    End If
    Loop Until EOF(1)
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  2. Dim sum As Integer
    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
    Do
    Input #1, a
    lon = Len(a)
    For j = 1 To lon
    an = Mid(a, j, 1)
    If Asc(an) < 1 Then
    a = Replace(a, an, "9")
    sum = sum + 1
    End If
    Next
    If sum > 0 Then Print #2, sum
    sum = 0
    Loop Until EOF(1)
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  3. Dim a() As String
    Private Sub Form_Load()
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, n
    For c = 1 To Val(n + (n - 1))
    ans = 0
    Line Input #1, x
    If x <> "" Then
    ReDim a(Len(x))
    For i = 1 To Len(x)
    If Asc(Mid(x, i, 1)) < 0 Then a(i) = Mid(x, i, 1)
    Next i
    For i = 1 To Len(x)
    For j = i + 1 To Len(x)
    If a(i) = a(j) Then a(j) = ""
    Next j
    Next i
    For i = 1 To Len(x)
    If a(i) <> "" Then ans = ans + 1
    Next i
    Print #2, ans
    End If
    Next c
    Close #2
    Close #1
    End
    End Sub

    回覆刪除