2010年3月23日 星期二

字串處理

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

5 則留言:

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

    回覆刪除
  2. Private Sub Form_Load()
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, x
    For j = 1 To x
    ans = 0
    Line Input #1, ss
    For i = 1 To Len(ss)
    If ("A" <= Mid(ss, i, 1)) And (Mid(ss, i, 1) <= "z") Then
    ans = ans + 1
    End If
    Next i
    Print #2, ans
    Next j
    Close #2
    Close #1
    End Sub
    普通的 判斷大小

    回覆刪除
  3. Dim str(50) As String
    Dim aa(1000) As String
    Dim x As String
    Private Sub Form_Load()
    Open App.Path & "/in.txt" For Input As #1
    Open App.Path & "/out.txt" For Output As #2
    n = 0
    Do Until EOF(1)
    Input #1, x
    str(n) = x
    n = n + 1
    Loop
    ans = 0
    For i = 1 To n - 1
    For j = 1 To Len(str(i))
    aa(j) = Mid(str(i), j, 1)
    If aa(j) > "A" And aa(j) < "z" Then
    ans = ans + 1
    End If
    Next j
    Print #2, ans
    ans = 0
    Next i
    Close #2
    Close #1
    End Sub

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

    回覆刪除
  5. 高仔好,
    這題會不會太簡單了一點呢?
    而放了這麼久才做。

    回覆刪除