Dim n 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, n Call A1(n) Next Close Close End End Sub
Sub A1(a) y = 0: x = 0 For i = 1 To Len(a) Step 2 x = Val(Mid(a, i, 2)) + (Val(y) * (10)) y = x Mod 11 Print x; y x = 0 Next If y = 0 Then Print #2, "1" Else Print #2, "0" 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 jj = 1 To N Line Input #1, X A = 0: B = 0 For i = 1 To Len(X) If i Mod 2 = 1 Then A = A + Val(Mid(X, i, 1)) Else B = B + Val(Mid(X, i, 1)) End If Next i
C = Abs(A - B) If C = 0 Or C Mod 11 = 0 Then Print #2, 1 Else Print #2, 0 End If
柯佑,arro好, 你們的程式都正確。 arro的方式,可以為任意數字的倍數的題目,很好。 柯佑的方式,是原來就先知道11的倍數的算法,也可以。 但是,If C = 0 Or C Mod 11 = 0 Then 這裡直接用 if c mod 11 = 0 then 就可以了吧。 (或是將0當成false, if c mod 11 then ... else ...)
Dim n
回覆刪除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, n
Call A1(n)
Next
Close
Close
End
End Sub
Sub A1(a)
y = 0: x = 0
For i = 1 To Len(a) Step 2
x = Val(Mid(a, i, 2)) + (Val(y) * (10))
y = x Mod 11
Print x; y
x = 0
Next
If y = 0 Then Print #2, "1" Else Print #2, "0"
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 jj = 1 To N
Line Input #1, X
A = 0: B = 0
For i = 1 To Len(X)
If i Mod 2 = 1 Then
A = A + Val(Mid(X, i, 1))
Else
B = B + Val(Mid(X, i, 1))
End If
Next i
C = Abs(A - B)
If C = 0 Or C Mod 11 = 0 Then
Print #2, 1
Else
Print #2, 0
End If
Next jj
Close #2
Close #1
End
End Sub
柯佑,arro好,
回覆刪除你們的程式都正確。
arro的方式,可以為任意數字的倍數的題目,很好。
柯佑的方式,是原來就先知道11的倍數的算法,也可以。
但是,If C = 0 Or C Mod 11 = 0 Then
這裡直接用 if c mod 11 = 0 then 就可以了吧。
(或是將0當成false, if c mod 11 then ... else ...)
熊掌好,
回覆刪除C = 0
所以C mod 11 還是0 !!
謝老師。