Problem5:字串處理(10%)

Solomon posted @ 2010年8月14日 08:45 in 98程式設計模擬試題 , 1240 阅读

 Problem5:字串處理(10%) 

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

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim fileContents As String
        fileContents = My.Computer.FileSystem.ReadAllText(Application.StartupPath & "\Test5.txt")
        Dim row() = Split(fileContents, vbNewLine)

        Dim str1 = ""
        For i As Integer = 1 To Val(row(0))
            If row(i) = "" Then Exit For
            Dim c = 0
            Dim a = row(i)
            For j As Integer = 1 To a.Length
                If Asc(Mid(a, j, 1)) >= 97 And Asc(Mid(a, j, 1)) <= 122 Then
                    c = c   1
                ElseIf Asc(Mid(a, j, 1)) >= 65 And Asc(Mid(a, j, 1)) <= 90 Then
                    c = c   1
                End If
            Next
            str1 = str1 & c & vbNewLine
        Next
        My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\result5.txt", str1, False)

        End
    End Sub
End Class
題目沒說明字串裡的英文字大小寫,為了以防萬一,就多了一個判斷  大寫也算進去
 
話說半夜練習程式安靜許多
我都不想睡了

 

Alyssa 说:
2022年12月14日 20:43

This program will take a string as input and output the number of English characters in that string. To do this, we will first need to establish what an English character is. For our purposes, an English character cbd health benefits is any letter in the 26-character Latin alphabet. With this definition in mind, we can iterate through the string and keep track of how many characters we encounter that match our definition. Finally, we can output the total number of English characters that were found in the string.

zaiya 说:
2022年12月27日 03:06

There are a number of different algorithms that can be used to perform these real estate agencies Oxnard operations, and the choice of algorithm often depends on the specific requirements of the application. For example, some algorithms may be faster but use more memory, while others may be slower but use less memory.

charlly 说:
2023年1月04日 14:12

When given a string as input, this software will output how many English characters are present. We must first define what an English character is in order to accomplish this. Any letter in the Latin alphabet's diamond rings 26 characters counts as an English character for our purposes.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter