Private Sub Form_Load() Me.Hide Dim a, x, n, c, e(99) As Long Dim d(99) As String Open App.Path & "/in.txt" For Input As #1 Open App.Path & "/out.txt" For Output As #2 Input #1, x, n
a = x * n c = Len(a)
For i = 1 To c d(i) = Mid(a, i, 1) Next
For i = 0 To 9 For y = 0 To 9 If d(i) = y Then e(y) = e(y) + 1 Next Next
For i = 0 To 9 If e(i) = 0 Then Else Print #2, i & e(i), End If Next
Private Sub Form_Load() Me.Hide Dim a, x, n, c, e(9) As Long Dim d(99) As String Open App.Path & "/in.txt" For Input As #1 Open App.Path & "/out.txt" For Output As #2 Input #1, x, n
a = x * n c = Len(a)
For i = 1 To c d(i) = Mid(a, i, 1) Next
For i = 0 To c For y = 0 To 9 If d(i) = y Then e(y) = e(y) + 1 Next Next
For i = 0 To 9 If e(i) = 0 Then Else Print #2, i & e(i), End If Next
Private Sub Form_Load() Me.Hide Dim a, x, n, c, e(10) As Long Dim d(99) As String Open App.Path & "/in.txt" For Input As #1 Open App.Path & "/out.txt" For Output As #2 Input #1, x, n a = x * n c = Len(a)
For i = 1 To c For y = 0 To 9 d(i) = Mid(a, i, 1) If d(i) = y Then e(y) = e(y) + 1 If i = c Then If e(y) <> 0 Then Print #2, y & e(y) & " "; End If Next Next
Private Sub Form_Load() Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Dim e(10) As Long Dim d(99) As String Input #1, X1, Y1 a = X1 * Y1 b = Len(a) For i = 1 To b For j = 0 To 9 d(i) = Mid(a, i, 1) If d(i) = j Then e(j) = e(j) + 1 If i = b Then If e(j) <> 0 Then Print #2, j & e(j) & " "; End If Next j Next i Close #2 Close #1 End End Sub
Private Sub Form_Load()
回覆刪除Me.Hide
Dim a, x, n, c, e(99) As Long
Dim d(99) As String
Open App.Path & "/in.txt" For Input As #1
Open App.Path & "/out.txt" For Output As #2
Input #1, x, n
a = x * n
c = Len(a)
For i = 1 To c
d(i) = Mid(a, i, 1)
Next
For i = 0 To 9
For y = 0 To 9
If d(i) = y Then e(y) = e(y) + 1
Next
Next
For i = 0 To 9
If e(i) = 0 Then
Else
Print #2, i & e(i),
End If
Next
Close
Close
End
End Sub
小冰好,程式有小錯誤
回覆刪除1.你程式做了"太多"不必要的事情
2.直接定義陣列(99) 不是個好習慣
3.你 For i = 0 To 9 如果 a 長度大於9呢?
4.陣列e()其實只需要宣告e(9)
尤其是第一點,太多地方可以改進囉
感覺想的太少 程式做出來都有瑕疵
回覆刪除還得了解的更深入
Private Sub Form_Load()
Me.Hide
Dim a, x, n, c, e(9) As Long
Dim d(99) As String
Open App.Path & "/in.txt" For Input As #1
Open App.Path & "/out.txt" For Output As #2
Input #1, x, n
a = x * n
c = Len(a)
For i = 1 To c
d(i) = Mid(a, i, 1)
Next
For i = 0 To c
For y = 0 To 9
If d(i) = y Then e(y) = e(y) + 1
Next
Next
For i = 0 To 9
If e(i) = 0 Then
Else
Print #2, i & e(i),
End If
Next
Close
Close
End
End Sub
勉強算可以了
回覆刪除現在先不求速度,想清楚再做吧
這個假日就想要怎樣用一個迴圈完成它吧
一個迴圈 是這個意思嗎= =?
回覆刪除一個雙層迴圈
Private Sub Form_Load()
Me.Hide
Dim a, x, n, c, e(10) As Long
Dim d(99) As String
Open App.Path & "/in.txt" For Input As #1
Open App.Path & "/out.txt" For Output As #2
Input #1, x, n
a = x * n
c = Len(a)
For i = 1 To c
For y = 0 To 9
d(i) = Mid(a, i, 1)
If d(i) = y Then e(y) = e(y) + 1
If i = c Then
If e(y) <> 0 Then Print #2, y & e(y) & " ";
End If
Next
Next
Close
Close
End
End Sub
很好,接近我想要的樣子了。
回覆刪除不過一直想跟你說
d(i) = Mid(a, i, 1)
If d(i) = y Then e(y) = e(y) + 1
這邊
可以直接改成
y = mid(a,i,1)
e(y)=e(y)+1
或是
e(d(i))=e(d(i))+1
其實那個d()陣列沒有必要啦
Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Dim e(10) As Long
Dim d(99) As String
Input #1, X1, Y1
a = X1 * Y1
b = Len(a)
For i = 1 To b
For j = 0 To 9
d(i) = Mid(a, i, 1)
If d(i) = j Then e(j) = e(j) + 1
If i = b Then
If e(j) <> 0 Then Print #2, j & e(j) & " ";
End If
Next j
Next i
Close #2
Close #1
End
End Sub
哲好,
回覆刪除程式正確。
if i=b then
這一部分,在雙迴圈中,有些浪費執行檢查時間,反正一定是最後會到達i=b,那麼就在外圈的地方,少一次,只有1 to b-1
然後,雙迴圈執行完了之後,在雙迴圈之後,再加上一次內迴圈的部分,這一次,就是用 i=b的值去做的。