2012年2月18日 星期六

字串處理

給一個字串,請寫一個程式,計算此字串中,英文字元有幾個?
輸入說明:
輸入檔第一行表示有幾組測試資料,第二行開始的每一行即為一筆測試資料,每行最多
有1000 個字元。
輸出說明:
對每一筆測試資料,輸出字串中英文字元的個數。
輸入範例:
2
abc123def456
133adfag3428a2fwqgq2
輸出範例:
6
11

5 則留言:

  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, x
    For i = 1 To x
    Line Input #1, a
    ans = 0
    n = Len(a)
    For y = 1 To n
    b = LCase(Mid(a, y, 1))
    If b >= "a" And b <= "z" Then ans = ans + 1
    Next
    Print #2, ans
    Next
    Close
    Close
    End
    End Sub

    回覆刪除
  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
    Line Input #1, x
    a = Len(x)
    ans = 0
    For j = 1 To a
    c = LCase(Mid(x, j, 1))
    If c >= "a" And "z" >= c Then ans = ans + 1
    Next j
    Print #2, ans
    Next i
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  3. 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 i = 1 To n
    Line Input #1, x
    ans = 0
    a = Len(x)
    For j = 1 To a
    b = LCase(Mid(x, j, 1))
    If b >= "a" And b <= "z" Then ans = ans + 1
    Next j
    Print #2, ans
    Next i
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  4. 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
    ans = 0
    Line Input #1, r
    For j = 1 To Len(r)
    q = LCase(Mid(r, j, 1))
    If q >= "a" And q <= "z" Then ans = ans + 1
    Next j
    Print #2, ans
    Next i
    Close #1
    Close #2
    End
    End Sub

    回覆刪除
  5. 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
    Line Input #1, x
    ans = 0
    a = Len(x)
    For j = 1 To a
    y = LCase(Mid(x, j, 1))
    If y <> "a" And y <> "b" And y <> "c" And y <> "d" And y <> "e" And y <> "f" And y <> "g" And y <> "h" And y <> "i" And y <> "j" And y <> "k" And y <> "l" And y <> "m" And y <> "n" And y <> "o" And y <> "p" And y <> "q" And y <> "r" And y <> "s" And y <> "t" And y <> "u" And y <> "v" And y <> "w" And y <> "x" And y <> "y" And y <> "z" Then
    ans = ans + 0
    Else
    ans = ans + 1
    End If
    Next j
    Print #2, ans
    Next i
    Close #2
    Close #1
    End
    End Sub

    回覆刪除