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, t For i = 1 To t Input #1, m, n Call A1(m, n) Next Close Close End End Sub
Sub A1(a, b)
Do While Len(a) <> Len(b) If Len(a) > Len(b) Then b = "0" & b If Len(a) < Len(b) Then a = "0" & a Loop
ans = 0 Dim s, ss ReDim s(Len(a)), ss(Len(a)) For i = Len(a) To 1 Step -1 s(i) = Mid(a, i, 1) ss(i) = Mid(b, i, 1) If Val(s(i)) + Val(ss(i)) + tmp > 9 Then ans = ans + 1: tmp = Val(s(i)) + Val(ss(i)) + tmp - 9 Else tmp = 0 Next
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, N For j = 1 To N Input #1, X, Y List1.Clear: List2.Clear List3.Clear: ans = 0 List3.AddItem 0
For i = 1 To Len(X) List1.AddItem Mid(X, i, 1) Next i
For i = 1 To Len(Y) List2.AddItem Mid(Y, i, 1) Next i
If Len(X) > Len(Y) Then max_len = Len(X) Else max_len = Len(Y)
For i = 0 To max_len - 1 If Val(List1.List(i)) + Val(List2.List(i)) + Val(List3.List(i)) >= 10 Then List3.AddItem 1: ans = ans + 1 Next i
Print #2, ans Next j Close #2 Close #1 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, N For j = 1 To N Input #1, X, Y List1.Clear: List2.Clear List3.Clear: ans = 0 List3.AddItem 0
For i = Len(X) To 1 Step -1 List1.AddItem Mid(X, i, 1) Next i
For i = Len(Y) To 1 Step -1 List2.AddItem Mid(Y, i, 1) Next i
If Len(X) > Len(Y) Then max_len = Len(X) Else max_len = Len(Y)
For i = 0 To max_len - 1 If Val(List1.List(i)) + Val(List2.List(i)) + Val(List3.List(i)) >= 10 Then List3.AddItem 1: ans = ans + 1 Next i
Print #2, ans Next j Close #2 Close #1 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, t
For i = 1 To t
Input #1, m, n
Call A1(m, n)
Next
Close
Close
End
End Sub
Sub A1(a, b)
Do While Len(a) <> Len(b)
If Len(a) > Len(b) Then b = "0" & b
If Len(a) < Len(b) Then a = "0" & a
Loop
ans = 0
Dim s, ss
ReDim s(Len(a)), ss(Len(a))
For i = Len(a) To 1 Step -1
s(i) = Mid(a, i, 1)
ss(i) = Mid(b, i, 1)
If Val(s(i)) + Val(ss(i)) + tmp > 9 Then ans = ans + 1: tmp = Val(s(i)) + Val(ss(i)) + tmp - 9 Else tmp = 0
Next
Print #2, ans
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, N
For j = 1 To N
Input #1, X, Y
List1.Clear: List2.Clear
List3.Clear: ans = 0
List3.AddItem 0
For i = 1 To Len(X)
List1.AddItem Mid(X, i, 1)
Next i
For i = 1 To Len(Y)
List2.AddItem Mid(Y, i, 1)
Next i
If Len(X) > Len(Y) Then max_len = Len(X) Else max_len = Len(Y)
For i = 0 To max_len - 1
If Val(List1.List(i)) + Val(List2.List(i)) + Val(List3.List(i)) >= 10 Then List3.AddItem 1: ans = ans + 1
Next i
Print #2, ans
Next j
Close #2
Close #1
End
End Sub
輸入範例:
3
123 456
555 555
999 1
輸出範例:
0
3
3
柯佑好,
回覆刪除'你的程式正確。
哦,不對,找到你的小錯誤了,
List3.AddItem 1
你只有在進位時才在第3個listbox中加數字,那麼不進位的,你會出問題。
arro好,
你的程式應該有個小錯誤,那個進位後的數,應該是整除10而不是減9。
tmp = Val(s(i)) + Val(ss(i)) + tmp - 9
或者,反正進位的話,都只進1,所以,直接tmp=1也可以。
(兩數相加的,找不出會進2的)
熊掌好,
回覆刪除好像不是那個問題呢!!
val(Val(List3.List(i))
若是空的會 傳回0
不過真的有錯
從數字尾巴相加才對
原本
1 4
2 5
3 6
修改後正確應為
3 6
2 5
1 4
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, N
For j = 1 To N
Input #1, X, Y
List1.Clear: List2.Clear
List3.Clear: ans = 0
List3.AddItem 0
For i = Len(X) To 1 Step -1
List1.AddItem Mid(X, i, 1)
Next i
For i = Len(Y) To 1 Step -1
List2.AddItem Mid(Y, i, 1)
Next i
If Len(X) > Len(Y) Then max_len = Len(X) Else max_len = Len(Y)
For i = 0 To max_len - 1
If Val(List1.List(i)) + Val(List2.List(i)) + Val(List3.List(i)) >= 10 Then List3.AddItem 1: ans = ans + 1
Next i
Print #2, ans
Next j
Close #2
Close #1
End
End Sub
對耶 好像進位用加的會找不到一次就進2的
回覆刪除tmp好像只能是1