## 2010年10月22日星期五

### 棒球九宮格

輸入範例1：
7 13
10 2
5 8
-9 19
11 35
3 23
18 0
0 18
40 22
輸入範例2：
12 22
15 11
3 20
3 22
33 27
28 28
16 5
22 -5
35 35

輸出範例1：
1 21
輸出範例2：
2 28

#### 2 則留言:

1. Dim num(3, 3) As Integer
Open App.Path & "/in.txt" For Input As #1
Open App.Path & "/out.txt" For Output As #2
num(0, 2) = 8: num(1, 2) = 5: num(2, 2) = 8
num(0, 1) = 5: num(1, 1) = 2: num(2, 1) = 5
num(0, 0) = 8: num(1, 0) = 5: num(2, 0) = 8
For i = 1 To 9
Input #1, x, y
x = x / 10: y = y / 10
If Int(x) = x Or Int(y) = y Or x >= 3 Or y >= 3 Or x < 0 Or y < 0 Then
Else
x = Int(x): y = Int(y)
ans = ans + num(x, y)
num(x, y) = 0
End If
Next i
q = 0
For i = 0 To 2
kk = 0: k = 0
For j = 0 To 2
kk = kk + num(i, j)
k = k + num(j, i)
Next j
If kk = 0 Then q = q + 1
If k = 0 Then q = q + 1
Next i
Print #2, q, ans
Close #2
Close #1
End Sub

ㄚ揚

2. Dim Board(3, 3) As Integer
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Board(3, 1) = 8: Board(3, 2) = 5: Board(3, 3) = 8
Board(2, 1) = 5: Board(2, 2) = 2: Board(2, 3) = 5
Board(1, 1) = 8: Board(1, 2) = 5: Board(1, 3) = 8
For AL = 1 To 9
Input #1, X, Y
X = X / 10: Y = Y / 10
If X >= 0 And Y >= 0 And X <= 3 And Y <= 3 Then
If Int(X) <> X And Int(Y) <> Y And Board(X, Y) < 10 Then
X1 = Int(X) + 1: Y1 = Int(Y) + 1
Sum = Sum + Board(X1, Y1)
Board(X1, Y1) = Board(X1, Y1) + 10
End If
End If
Next AL
For I = 1 To 3
If Board(I, 1) > 10 And Board(I, 2) > 10 And Board(I, 3) > 10 Then sum1 = sum1 + 1
If Board(1, I) > 10 And Board(2, I) > 10 And Board(3, I) > 10 Then sum1 = sum1 + 1
Next I
Print #2, sum1 & " " & Sum
Close #2
Close #1
End
End Sub

BY小白