Private Sub Form_Load() Dim a(10) As Integer Dim b(10) As Integer Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Input #1, x, y Close #1 Max = 0 ans = 0 n = Len(x) If n > Max Then Max = n Do Until x = "" a(n) = Left(x, 1) x = Right(x, Len(x) - 1) n = n - 1 Loop m = Len(y) If m > Max Then Max = m Do Until y = "" b(m) = Left(y, 1) y = Right(y, Len(y) - 1) m = m - 1 Loop For i = 1 To Max If a(i) + b(i) > 9 Then ans = ans + 1 Next i Print #2, ans Close #2 End Sub
老師取數字 除了 mod 10 還有捨嚜方法呢? Private Sub Form_Load() Dim a(10) As Integer Dim b(10) As Integer Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Input #1, x, y Close #1 Max = 0 i = 1 Do Until x = 0 a(i) = x Mod 10 x = x \ 10 i = i + 1 Loop If i > Max Then Max = i l = 1 Do Until y = 0 b(l) = y Mod 10 y = y \ 10 l = l + 1 Loop If l > Max Then Max = l For i = 1 To Max If a(i) + b(i) > 9 Then ans = ans + 1: c = 1: a(i + 1) = a(i + 1) + 1 Next i Print ans Close #2 End Sub
Private Sub Form_Load() Open App.Path & "/in.txt" For Input As #1 Input #1, x, y Close #1 ans = 0 Do While x <> 0 And y <> 0 a = x Mod 10 b = y Mod 10 c = 0 If a + b + c >= 10 Then c = 1: ans = ans + 1 x = x \ 10 y = y \ 10 Loop Open App.Path & "/out.txt" For Output As #2 Print #2, ans Close #2 End Sub
Dim aa(10) As Integer Dim bb(10) As Integer Private Sub Form_Load() Open App.Path & "/in.txt" For Input As #1 Input #1, x, y If Len(x) > Len(y) Then A = x Else A = y End If aa(0) = x bb(0) = y SumAB = 0 For i = Len(A) To 1 Step -1 If Len(aa(0)) >= i Then aa(i) = Mid(aa(0), i, 1) If Len(bb(0)) >= i Then bb(i) = Mid(bb(0), i, 1) If aa(i) + bb(i) >= 10 Then SumAB = SumAB + 1 End If Next i Close #1 Open App.Path & "/out.txt" For Output As #2 Print #2, SumAB Close #2 End Sub
小白好,(還有其它人也是) 1. Open App.Path & "/in.txt" For Input As #1 -> Open App.Path & "\in.txt" For Input As #1 2.這題還是跟高仔他們一樣錯了吧。因為前面的進位而造成後面的進位呢? 11111 + 8889之類的進位呢? 3.所以,你們(全部)再重新將這題當成「大數加法」來做吧。將數字拆成字元陣列後,真的將它相加,於是,過程中,多用一個變數來記錄有幾次進位就好了吧。
Public Sub Form_Load() Dim a(100) As Integer Dim b(100) As Integer Me.Hide Open App.Path & "/in.txt" For Input As #1 Open App.Path & "/out.txt" For Output As #2 Input #1, x, y ans = 0 k = 1 Do Until x = 0 a(k) = x Mod 10 x = x \ 10 k = k + 1 Loop Min = k - 1 k = 1 Do Until y = 0 b(k) = y Mod 10 y = y \ 10 k = k + 1 Loop If k - 1 < Min Then Min = k - 1
For i = 1 To Min If (a(i) + b(i)) >= 10 Then a(i + 1) = a(i + 1) + 1: ans = ans + 1 Next i Print #2, ans Close #1 Close #2 End End Sub
文章有錯字喔@@挼果香加 這樣會不懂意思
回覆刪除Private Sub Form_Load()
回覆刪除Dim a(10) As Integer
Dim b(10) As Integer
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, x, y
Close #1
Max = 0
ans = 0
n = Len(x)
If n > Max Then Max = n
Do Until x = ""
a(n) = Left(x, 1)
x = Right(x, Len(x) - 1)
n = n - 1
Loop
m = Len(y)
If m > Max Then Max = m
Do Until y = ""
b(m) = Left(y, 1)
y = Right(y, Len(y) - 1)
m = m - 1
Loop
For i = 1 To Max
If a(i) + b(i) > 9 Then ans = ans + 1
Next i
Print #2, ans
Close #2
End Sub
Dim ans As Integer
回覆刪除Private Sub Form_Load()
Open App.Path & "\in.txt" For Input As #1
Input #1, X1, X2
Close #1
If X1 > X2 Then
x = X1
y = X2
Else
y = X1
x = X2
End If
Open App.Path & "\out.txt" For Output As #2
Do
a = x Mod 10
b = y Mod 10
xx = a + b + c
If xx >= 10 Then
ans = ans + 1
c = x \ 10
Else
c = 0
End If
x = x \ 10
y = y \ 10
Loop Until x = 0
Print #2, ans
Close #2
End Sub
胖胖瑋
回覆刪除你的 好像只有 3個位數,
而且 如果是255 555
答案結果是4喔
打錯 是255 5555 @@
回覆刪除作者已經移除這則留言。
回覆刪除Dim ans As Integer
回覆刪除Private Sub Form_Load()
Open App.Path & "\in.txt" For Input As #1
Input #1, X1, X2
Close #1
If X1 > X2 Then
x = X1
y = X2
Else
y = X1
x = X2
End If
ans = 0
Open App.Path & "\out.txt" For Output As #2
Do
a = x Mod 10
b = y Mod 10
xx = a + b + c
If xx >= 10 Then
ans = ans + 1
c = 1
Else
c = 0
End If
x = x \ 10
y = y \ 10
Loop Until x = 0
Print #2, ans
Close #2
End Sub
改好了@@
回覆刪除Y揚好,
回覆刪除1.你的程式又是用字串處理數字,不是好方式,試著用阿瑋的方式吧。
2.你的程式,似乎沒考慮到進位後的那個1,會不會造成下次的進位影響哦。
阿瑋好,
1.你的程式第一個是想用 c = xx \ 10 吧。不過,反正只有兩個數相加,不會大於1,於是第二次改程式,就改成c = 1。
2. 用原來的想法,可以更直接哦。
xx=a+b+c
c = xx \10
ans = ans +c
這樣還可以省掉那個if的判斷。
老師取數字 除了 mod 10 還有捨嚜方法呢?
回覆刪除Private Sub Form_Load()
Dim a(10) As Integer
Dim b(10) As Integer
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, x, y
Close #1
Max = 0
i = 1
Do Until x = 0
a(i) = x Mod 10
x = x \ 10
i = i + 1
Loop
If i > Max Then Max = i
l = 1
Do Until y = 0
b(l) = y Mod 10
y = y \ 10
l = l + 1
Loop
If l > Max Then Max = l
For i = 1 To Max
If a(i) + b(i) > 9 Then ans = ans + 1: c = 1: a(i + 1) = a(i + 1) + 1
Next i
Print ans
Close #2
End Sub
苦惱 還是跳脫不了mod 或是 字串形式...= ="
回覆刪除輸入用255 5555 輸出為2
Private Sub Form_Load()
Open App.Path & "/in.txt" For Input As #1
Input #1, x, y
Close #1
ans = 0
Do While x <> 0 And y <> 0
a = x Mod 10
b = y Mod 10
c = 0
If a + b + c >= 10 Then c = 1: ans = ans + 1
x = x \ 10
y = y \ 10
Loop
Open App.Path & "/out.txt" For Output As #2
Print #2, ans
Close #2
End Sub
Y揚好,
回覆刪除1.對數字的處理,本來就適合用數學運算囉,所以就是mod \ +-*/這些方法囉。
2.c = 1 做什麼呢?
高仔好,
1.就用mod 方式吧。
2.你舉例的輸入輸出,不好吧。不是特殊的例子。
比如: 455 5555 你的輸出會如何? 錯了吧。
3.你的
c=0
放錯位置了。
Dim aa(10) As Integer
回覆刪除Dim bb(10) As Integer
Private Sub Form_Load()
Open App.Path & "/in.txt" For Input As #1
Input #1, x, y
If Len(x) > Len(y) Then
A = x
Else
A = y
End If
aa(0) = x
bb(0) = y
SumAB = 0
For i = Len(A) To 1 Step -1
If Len(aa(0)) >= i Then aa(i) = Mid(aa(0), i, 1)
If Len(bb(0)) >= i Then bb(i) = Mid(bb(0), i, 1)
If aa(i) + bb(i) >= 10 Then
SumAB = SumAB + 1
End If
Next i
Close #1
Open App.Path & "/out.txt" For Output As #2
Print #2, SumAB
Close #2
End Sub
小白好,(還有其它人也是)
回覆刪除1.
Open App.Path & "/in.txt" For Input As #1 ->
Open App.Path & "\in.txt" For Input As #1 2.這題還是跟高仔他們一樣錯了吧。因為前面的進位而造成後面的進位呢? 11111 + 8889之類的進位呢?
3.所以,你們(全部)再重新將這題當成「大數加法」來做吧。將數字拆成字元陣列後,真的將它相加,於是,過程中,多用一個變數來記錄有幾次進位就好了吧。
Public Sub Form_Load()
回覆刪除Dim a(100) As Integer
Dim b(100) As Integer
Me.Hide
Open App.Path & "/in.txt" For Input As #1
Open App.Path & "/out.txt" For Output As #2
Input #1, x, y
ans = 0
k = 1
Do Until x = 0
a(k) = x Mod 10
x = x \ 10
k = k + 1
Loop
Min = k - 1
k = 1
Do Until y = 0
b(k) = y Mod 10
y = y \ 10
k = k + 1
Loop
If k - 1 < Min Then Min = k - 1
For i = 1 To Min
If (a(i) + b(i)) >= 10 Then a(i + 1) = a(i + 1) + 1: ans = ans + 1
Next i
Print #2, ans
Close #1
Close #2
End
End Sub
8分02
9999+33
回覆刪除有幾次進位?
要小心細節。
要能多想到特殊的「正確」輸入值。
熊掌