Private Sub Form_Load() Me.Hide Open App.Path & "\out.txt" For Output As #2 Open App.Path & "\in.txt" For Input As #1
Input #1, r
Do While Not EOF(1) Input #1, n x = 0 c1 = 0 c2 = 0 For i = 1 To Len(n) x = Mid(n, i, 1) If i Mod 2 = 0 Then c1 = c1 + x Else c2 = c2 + x Next If n = 0 Then Print #2, "0" Else If (c1 - c2) = 0 Or (c1 - c2) Mod 11 = 0 Then Print #2, "1" Else Print #2, "0" End If Loop Close #1 End End Sub ----------- in.txt 2 0 123456784 out.txt 0 1
Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2
Dim INS As String, X, Y, ch Input #1, times
For i = 1 To times X = 0: Y = 0: ch = 0 Input #1, INS If INS = 0 Then ch = 1 For k = 1 To Len(INS) If k Mod 2 = 0 Then X = X + Val(Mid(INS, k, 1)) Else Y = Y + Val(Mid(INS, k, 1)) End If
Next
If ch = 0 And ((X - Y) = 0 Or (X - Y) Mod 11 = 0) Then Print #2, "1" Else Print #2, "0"
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(n) For i = 1 To Len(n) Step 3 m = Mid(n, i, 3) + Val(k) k = (m Mod 11) * 10 Next If k = 0 Then Print #2, "1" Else Print #2, "0" End Sub
Private Sub Form_Load()
回覆刪除Me.Hide
Dim times As Byte
Dim X As String
Dim Odd As Integer
Dim Even As Integer
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, times
For i = 1 To times
Input #1, X
Odd = 0
Even = 0
For j = 1 To Len(X)
If j Mod 2 = 0 Then
Odd = Odd + Val(Mid(X, j, 1))
Else
Even = Even + Val(Mid(X, j, 1))
End If
Next j
If (Abs(Odd - Even) = 0) Or (Abs(Odd - Even) Mod 11 = 0) Then Print #2, "1" Else Print #2, "0"
Next i
Close #2
Close #1
End
End Sub
佑好,
回覆刪除程式正確。
有個小地方,(Abs(Odd - Even) = 0) Or (Abs(Odd - Even) Mod 11 = 0) 這一個判斷,是不是又多做了一半呢?
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\out.txt" For Output As #2
Open App.Path & "\in.txt" For Input As #1
Input #1, r
Do While Not EOF(1)
Input #1, n
x = 0
c1 = 0
c2 = 0
For i = 1 To Len(n)
x = Mid(n, i, 1)
If i Mod 2 = 0 Then c1 = c1 + x Else c2 = c2 + x
Next
If n = 0 Then
Print #2, "0"
Else
If (c1 - c2) = 0 Or (c1 - c2) Mod 11 = 0 Then Print #2, "1" Else Print #2, "0"
End If
Loop
Close #1
End
End Sub
-----------
in.txt
2
0
123456784
out.txt
0
1
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Dim INS As String, X, Y, ch
Input #1, times
For i = 1 To times
X = 0: Y = 0: ch = 0
Input #1, INS
If INS = 0 Then ch = 1
For k = 1 To Len(INS)
If k Mod 2 = 0 Then
X = X + Val(Mid(INS, k, 1))
Else
Y = Y + Val(Mid(INS, k, 1))
End If
Next
If ch = 0 And ((X - Y) = 0 Or (X - Y) Mod 11 = 0) Then Print #2, "1" Else Print #2, "0"
Next
Close
Close
End
End Sub
//--------------
輸入:
5
24841983960
121
10989
54104512123451868
0
輸出:
0
1
1
0
0
//----------
佑貌似少了 0 的判斷 !?
老師說的多做一半是指 絕對值 嗎 !?
緣尉、arro好,
回覆刪除你們的程式和佑的程式一樣吧。雖然還算正確。
0是不是11的倍數呢?
0 mod 11是不是也是0呢?
熊掌好,
回覆刪除所以
(Abs(Odd - Even) Mod 11 = 0)
就可以了:D~
arro好,
絕對值是避免出現負數
因為不知道奇位相加是否大於偶位相加
佑好,
回覆刪除-121 mod 11會得到什麼呢?
還有前面我也忘了看清楚了,題目寫的是「正整數」
所以,也不會有0出現。(比賽的情況下)
熊掌好,
回覆刪除-121 mod 11 還是= 0
:)
負數出現是因為奇偶位數相減
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(n)
For i = 1 To Len(n) Step 3
m = Mid(n, i, 3) + Val(k)
k = (m Mod 11) * 10
Next
If k = 0 Then Print #2, "1" Else Print #2, "0"
End Sub
3:11