Dim N As String Dim A1 As Long Dim A2 As Long Dim A3 As String Dim A(10) As Integer Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Input #1, N Close #1 A1 = Val(Left(N, 4)) A2 = Val(Right(N, 4)) A3 = Str(A1 * A2)
Do Until B = Len(A3) B = B + 1 A(InStr("0123456789", Mid(A3, B, 1))) = A(InStr("0123456789", Mid(A3, B, 1))) + 1 Loop
Open App.Path & "\out.txt" For Output As #2 For i = 1 To 10 If A(i) <> 0 Then Print #2, (i - 1) & A(i); " "; Next i 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, b Call A1(a, b) Close Close End End Sub
Sub A1(a, b) Dim c, s(9) As Integer c = a * b For i = 1 To Len(c) m = Mid(c, i, 1) s(m) = s(m) + 1 Next For i = 0 To 9 If s(i) <> 0 Then Print #2, i & s(i) & " "; Next End Sub
Private Sub Form_Load()
回覆刪除Me.Hide
Dim k(10)
Open App.Path & "\out.txt" For Output As #2
Open App.Path & "\in.txt" For Input As #1
Input #1, x, y
a = x * y
m = Len(a)
For i = 1 To m
n = Mid(a, i, 1)
k(n) = k(n) + 1
Next i
For i = 0 To 9
If k(i) = 0 Then
Print #2, "";
Else
Print #2, i & k(i) & " ";
End If
Next i
Close #1
Close #2
End
End Sub
感覺你的 Print #2, ""; 這行是多餘的
回覆刪除緣尉好,
回覆刪除1.程式OK。
2.我正想說的話,arro說了。(謝謝你,arro,會看看別人的程式,找出優缺點,也是很重要的哦)
熊掌
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, y
ins = x * y
Dim s(9) As Integer
For i = 0 To 9
For j = 1 To Len(ins)
k = Mid(ins, j, 1)
If k = Val(i) Then s(i) = s(i) + 1
Next
Next
For i = 0 To 9
If s(i) <> 0 Then Print #2, i & s(i) & " ";
Next
Close #2
Close #1
End
End Sub
------
隨身碟找到了 =D
Arro好,
回覆刪除程式乍看可以,但是容易出錯,又太重複。
數字變數的長度len(ins)有定義跟沒定義會有不同。
找一下去年的討論。
數字其實還是適合用「取餘數」和「整除」來做。
熊掌ipad
Dim N As String
回覆刪除Dim A1 As Long
Dim A2 As Long
Dim A3 As String
Dim A(10) As Integer
Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Input #1, N
Close #1
A1 = Val(Left(N, 4))
A2 = Val(Right(N, 4))
A3 = Str(A1 * A2)
Do Until B = Len(A3)
B = B + 1
A(InStr("0123456789", Mid(A3, B, 1))) = A(InStr("0123456789", Mid(A3, B, 1))) + 1
Loop
Open App.Path & "\out.txt" For Output As #2
For i = 1 To 10
If A(i) <> 0 Then Print #2, (i - 1) & A(i); " ";
Next i
Close #2
End
End Sub
佑好,
回覆刪除程式可以,那主要的一行,看起來太複雜,不過也可以啦。
熊掌
Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Dim stor(10): Dim chk(10): Dim ans1(10)
Input #1, a, b
For ci = Len(a) To 1 Step -1
i = i + 1
For cj = Len(b) To 1 Step -1
j = j + 1
stor(i + j - 1) = stor(i + j - 1) + Mid(a, ci, 1) * Mid(b, cj, 1): chk(i + j - 1) = True
If stor(i + j - 1) > 9 Then
stor(i + j) = stor(i + j) + Val(Left(stor(i + j - 1), 1))
stor(i + j - 1) = Val(Right(stor(i + j - 1), 1))
If stor(i + j) > 9 Then
stor(i + j + 1) = stor(i + j + 1) + Val(Left(stor(i + j - 1), 1))
stor(i + j) = Val(Right(stor(i + j), 1))
chk(i + j + 1) = True
End If
chk(i + j) = True
End If
Next cj
j = 0
Next ci
i = 0
For i = 0 To 10
If chk(i) = True Then ans1(stor(i)) = ans1(stor(i)) + 1
Next i
For i = 0 To 9
If ans1(i) <> 0 Then Print #2, i & ans1(i) & " ";
Next i
Close #2
Close #1
End
End Sub
Jimmer好,
回覆刪除程式正確。
但是,你想做的是「大數運算」吧?
比賽時,是有時間限制的。
用最少的力氣去做。
熊掌
就想說現在有空研究一下
回覆刪除當時進位那邊一直出錯
頭腦整個有點混亂掉...
Jimmer好,
回覆刪除1+9999999要進位幾次?
取進位的方式用「\ 和mod」比較好,
大數加法先試試吧
熊掌
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, b
Call A1(a, b)
Close
Close
End
End Sub
Sub A1(a, b)
Dim c, s(9) As Integer
c = a * b
For i = 1 To Len(c)
m = Mid(c, i, 1)
s(m) = s(m) + 1
Next
For i = 0 To 9
If s(i) <> 0 Then Print #2, i & s(i) & " ";
Next
End Sub
2: 06