Private Sub Form_Load() Dim Times As Byte 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 Times = 0 For j = 1 To Len(X) If Mid(X, j, 1) >= "A" And Mid(X, j, 1) <= "z" Then Times = Times + 1 Next j
Private Sub Form_Load() Me.Hide Open App.Path & "\out.txt" For Output As #2 Open App.Path & "\in.txt" For Input As #1
Input #1, n For ii = 1 To n Line Input #1, m c = 0 For i = 1 To Len(m) If Asc(Mid(m, i, 1)) > 57 Then c = c + 1 Next Print #2, c Next Close #1 Close #2 End End Sub ------------------------ IN.TXT 4 abc123def456 133adfag3428a2fwqgq2 123AAAVCCSQWasdag l1IvAeji6國字 ------------------------ OUT.TXT 6 11 14 7
Private Sub Form_Load() Me.Hide 'x = Split("A Z a z") 'For i = 0 To UBound(x) 'Print Asc(x(i)) 'Next Open App.Path & "\out.txt" For Output As #2 Open App.Path & "\in.txt" For Input As #1
Input #1, n For ii = 1 To n Line Input #1, m c = 0 For i = 1 To Len(m) If (Asc(Mid(m, i, 1)) >= 65 And Asc(Mid(m, i, 1)) <= 90) Or (Asc(Mid(m, i, 1)) >= 97 And Asc(Mid(m, i, 1)) <= 122) Then c = c + 1 Next Print #2, c Next Close #1 Close #2 End End Sub
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, a
For k = 1 To a
Line Input #1, n
ans = 0
For i = 1 To Len(n)
If Asc(Mid(n, i, 1)) >= 65 And Asc(Mid(n, i, 1)) <= 122 Then ans = ans + 1
Next
Print #2, ans
Next
Close
Close
End
End Sub
/////////
輸入
2
abc123
llllllllllllllIIIIIIIIIIIIII111111111111111
輸出
3
28
Private Sub Form_Load()
回覆刪除Dim Times As Byte
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
Times = 0
For j = 1 To Len(X)
If Mid(X, j, 1) >= "A" And Mid(X, j, 1) <= "z" Then Times = Times + 1
Next j
Print #2, Times
Next i
Close #2
Close #1
/////////
輸入
2
123AAAVCCSQWasdag
l1IvAeji6國字
輸出
14
7
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\out.txt" For Output As #2
Open App.Path & "\in.txt" For Input As #1
Input #1, n
For ii = 1 To n
Line Input #1, m
c = 0
For i = 1 To Len(m)
If Asc(Mid(m, i, 1)) > 57 Then c = c + 1
Next
Print #2, c
Next
Close #1
Close #2
End
End Sub
------------------------
IN.TXT
4
abc123def456
133adfag3428a2fwqgq2
123AAAVCCSQWasdag
l1IvAeji6國字
------------------------
OUT.TXT
6
11
14
7
arro,佑,緣尉好,
回覆刪除你們三個都做一樣的方式,似乎是正確的。只是,
你們都偷懶了,有錯誤的機會。
要英文字,你們就用A~Z a~z來算,你們用的是A~z,ascii在這兩個中間沒有空了嗎?
A-65
Z-90
a-97
所以,91~96的ascii值的字,如果出來的話,是會出錯的哦。
不能省的檢查,別省略。
當然,不用的檢查,也別多做。
Private Sub Form_Load()
回覆刪除Me.Hide
'x = Split("A Z a z")
'For i = 0 To UBound(x)
'Print Asc(x(i))
'Next
Open App.Path & "\out.txt" For Output As #2
Open App.Path & "\in.txt" For Input As #1
Input #1, n
For ii = 1 To n
Line Input #1, m
c = 0
For i = 1 To Len(m)
If (Asc(Mid(m, i, 1)) >= 65 And Asc(Mid(m, i, 1)) <= 90) Or (Asc(Mid(m, i, 1)) >= 97 And Asc(Mid(m, i, 1)) <= 122) Then c = c + 1
Next
Print #2, c
Next
Close #1
Close #2
End
End Sub
緣尉好,
回覆刪除程式正確,但是,
Asc(Mid(m, i, 1)
這個動作重複做這麼多次,浪費時間,用個變數給它,只要做一次。