2019年1月25日 星期五

0125練習 uva11470

0125資料夾


UVA 11470題目

題意: N x N 方陣,最多10x10,算每一圈的數字和

vb版 解題參考,輸入 in.txt  輸出out.txt


https://uva.onlinejudge.org/external/114/11470.pdf
Public Class Form1
    Dim a(10, 10) As Integer '最多 10x10
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Hide()
        FileOpen(1, "in.txt", OpenMode.Input)
        FileOpen(3, "out.txt", OpenMode.Output)
        For fn = 1 To 1
            'If fn = 2 Then PrintLine(3)
            Do While True
                Dim n% = LineInput(fn)
                If n = 0 Then Exit Do
                For i = 0 To n - 1
                    Dim s = LineInput(fn)
                    Dim dat() = s.Split(" ")
                    For j = 0 To n - 1
                        a(i, j) = dat(j)
                    Next
                Next
                PrintLine(3, fxx(n))
            Loop
        Next
        End
    End Sub
    Dim dr() = {0, 1, 0, -1}
    Dim dc() = {1, 0, -1, 0}
    '       d 0 1 2 3
    Function fxx(ByVal n As Integer) As String
        If (n = 1) Then Return a(0, 0)
        fxx = ""
        Dim m = (n + 1) \ 2  '共幾圈
        Dim r, c, sum, k As Integer
        For i = 0 To m - 1 ' i
            sum = 0 : r = i : c = i
            k = n - 1 - 2 * i '每個方向幾個數字
            If k = 0 Then sum = a(r, c)
            For d = 0 To 3 '四個方向
                For j = 1 To k '每個方向幾個數字
                    r += dr(d) : c += dc(d) '下一個位置座標
                    sum += a(r, c)
                Next j
            Next d
            If i > 0 Then fxx &= " "
            fxx &= sum
        Next i
    End Function
End Class
 

2019年1月8日 星期二

Z2B VB筆試參考

練習卷下載


一、單選題:(3分,共12) 36%
01(  B3   )執行下列程式()結果輸出幾個G
02(  C75   )執行下列程式()結果輸出S=
03(  B6    )執行下列程式()結果輸出S=
' 程式()  4-9-1
For X = 15 To 2 Step -2
  Label1.Text &= "G"
  X = X - 3
Next X
' 程式()  4-9-2
Dim S = 0
For X = 5 To 20 Step 3
   S = S + X
Next
Label1.Text = "S = " & S
' 程式()  4-9-3
Dim S = 1, R = 1
For X = 2 To 15
   S = S + X * R
   R = R * (-1)
Next
Label1.Text = "S = " & S
04(  A3    )執行下列程式() 結果輸出S=
05(  D6    )執行下列程式()結果輸出幾個*?
06(  D20   )執行下列程式()結果輸出A+S=
' 程式()  4-9-4
Dim S = 0
For X = 2 To 7
  S = S + (X Mod 2)
Next
Label1.Text = "S = " & S
' 程式()  4-9-5
Dim A = 5, B = 13
For A = 2 To B Step 1
    If (A Mod 2 = 0) Then
      Label1.Text &= ""
    End If
Next
' 程式()
Dim A = 3, B = 7, S = 6
For A = 2 To B Step 2
    S = S + 2
Next A
Label1.Text = "A+S = " & A + S
07(  B6    )執行下列程式() 結果輸出S=
08(  c30   ) 執行下列程式() 結果輸出T=
09(  d15   ) 執行下列程式() 結果輸出S=
' 程式()
Dim A = 13, B = 5, S = 6
For A = 2 To B Step -2
    S = S + 2
Next A
Label1.Text = " S = " & S
'  程式()
Dim T = 0
For k =3 To 12 Step 3
  T = T + k
Next
Label1.Text = "T = " & T
'  程式()
Dim S = 0
For K = 2 to 16
  S = S + (K Mod 3)
Next K
Label1.Text = "S = " & S
10(  C  )For...Next敘述,若要中途跳出迴圈使用? (A) Exit Loop  (B) Quit For  (C) Exit For  (D) Quit Next
11(  C  )有關For...Next敘述,下列何者正確? (A)Next敘述後的控制變數,不可省略不寫 (B)增加值只能為正值
(C)
若增加值為1,則可省略不寫Step (D)增加值需小於初始值
12(  D  )有關For...Next敘述,下列何者正確? (A)若省略Step,則增加值為0  (B)若增加值為正,則需初值小於
等於0  (C)若終值為負,則增加值需為負 (D)控制變數A,若初值1,增值2,終值為5,寫成 For A=1 To 5 Step 2
二、填充題:每格2分,共21(42%)
' 程式()
Dim X,C,S As Integer
For X=3 To 13 Step 2
   C=C+1 : S=S+X
Next X
X=_15__C=_6__S=__48___
'  程式(十一)
Dim X,C,S As Integer
For X=18 To 12 Step - 3
   C=C+1 : S=S+X
Next X
X=_9__C=_ 3__S=___45___
'  程式(十二)
Dim X,C,S As Integer
For X=32 To 15 Step - 5
   S=S+X : C=C+1
Next X
執行後,C=__4_,X=__12__,S=__98___
' 程式(十三)
Dim C,X,Y,S As Integer
For X=4 To 15 Step 3
  For Y=2 To 7 Step 2
    C=C+1 : S=S+Y
  Next Y
Next X
X=_16_,Y=_8_,C=_12_,S=__48__
' 程式(十四)
Dim C,X,Y,S As Integer
For X=2 To 13 Step 4
  For Y=X+1 To 9 Step 3
    C=C+1 : S=S+Y
  Next Y
Next X
X=_14_,Y=_11_,C=_4_,S=__25__
' 程式(十五)
Dim C,X,Y,S As Integer
For X=16 To 1 Step  - 5
  For Y=11 To X Step -3
    C=C+1 : S=S+X+Y
  Next Y
Next X
X=_-4_,Y=_-1_,C=_7_,S=__83__


三、陣列宣告:(每格15) ,寫元素個數、及共佔用記憶體(Bytes)
    {本題不作答的話,第1大題配分調整為每題4.8}
元素個
佔用記憶體(Bytes)
1Dim  A(3,4) AS Short
(3+1)*(4+1) = 20
2* 20 = 40
2Dim  B(2,3,2) AS Byte
(2+1)* (3+1)*(2+1) = 36
* 36 = 36
3Dim  C(5) AS Long
(5+1) = 6
* 6 = 48
4Dim  D(7) AS Integer
(7+1) = 8
* 8 = 32
5Dim  Ee(6,3) AS Single
(6+1)*(3+1) = 28
*28 = 112
6Dim  F(1,3,2) AS Double
(1+1)* (3+1)*(2+1) = 24
* 24 = 192
7Dim  G(3,2,3) AS Date
(3+1)* (2+1)* (3+1) = 48
* 48 = 384
() 依以上的宣告做答:(今天練習)
  8、問A.Length = ___20____                   9、問Ubound(A,2) = ____4____
  10、問Ubound(Ee,2) = ___3_____               11、問Lbound(F,1) = ___0______
四、Do迴圈練習
01(  A  )執行下列程式() 結果輸出S= (A) 10  (B) 18   (C) 23  (D) 30
02(  A  )執行下列程式() 後,何者正確? (A) A=7  (B) S=12    (C) S=5  (D) A=3
03(  B  )執行下列程式()結果輸出S= (A) - 25  (B) - 12   (C) 10  (D) 20
' 程式()  4-27-5
Dim A = 1, S = 0
Do While A < 5
  If A Mod 2 = 1 Then
       S = 3 * S
  Else
       S = S + A
  End If
  A = A + 1
Loop
Label1.Text = "S = " & S
'  程式(十四)自訂練習
Dim A = 3, B = 2, S = 5
 Do While S < 13
    S = S + A
    A = A + B
 Loop
 Label1.Text = "A,S = " & A & "," & S
' 程式()  4-26-1
Dim A = 5, B = 10, S = 0
Do While A >= -1
   S = S + 1
   B = B - 3
   A = A - 3
Loop
Label1.Text = "A*B*S = " & A * B * S
04(  A  )執行下列程式() 結果輸出S= (A) 4  (B) 8   (C) 12  (D) 15
05(  C  )執行下列程式() 結果輸出B= (A) 5  (B) 7   (C) 11  (D) 15
06(  B  )執行下列程式() 結果輸出B= (A) 0  (B) 6   (C) 21  (D) 30
' 程式()  4-26-2
Dim A = 15, S = 0
Do
   If A Mod 3 = 0 Then
       S = S + 1
   End If
   A = A - 1
Loop While A > 3
Label1.Text = "S = " & S
' 程式()  4-27-3
Dim A = 1, B = 5
 While B < 10
     B = B + 2 * A
     A = A + 1
 End While
Label1.Text = "B = " & B
' 程式()  4-27-4
Dim A = 42, B = 30, C = 1
Do While C <> 0
    C = A Mod B
    If C <> 0 Then
        A = B
        B = C
    End If
Loop
Label1.Text = "B = " & B
07(  A  )Do...Loop敘述,若要中途跳出迴圈使用? (A) Exit Do  (B) Quit Do  (C) Exit Loop  (D) Quit Loop
08(  B  ) Do...Loop敘述,下列何者有誤? (A) 前測式可能執行0  (B) 前測式最少會執行1 
(C)
後測式最少會執行1 (D) Do … Loop While(條件) 是後測式

補充函數:Int , Abs , Sign, Sqrt, Fix, Cint , Year , Month , Day , Now, Hour, Minute, Second,例題如下
會考選擇
01(  1  )執行VB的內建函數Math.SIGN(2.56)後,其值為何?
02(  -1  )執行VB的內建函數Math.SIGN(-2.56)後,其值為何?
03(  2.5  )執行VB的內建函數Math.SQRT( 6.25 )後,其值為何?
04(  -7  )執行VB的內建函數INT(-6.25)後,其值為何?
05(  2  )執行VB的內建函數INT(2.56)後,其值為何?
05(  2  )執行VB的內建函數Fix(2.56)後,其值為何?
06(  2.56  )執行VB的內建函數Math.ABS(-2.56)後,其值為何?
07(  6.25  )執行VB的內建函數Math.ABS(6.25)後,其值為何?
18(  2019  )執行VB的內建函數Year(Now)後,其值為何?
19(  1  )執行VB的內建函數Month(Now)後,其值為何?
10(  13  )執行VB的內建函數Hour(#1:23:45 PM#)後,其值為何?
11(  23  )執行VB的內建函數Minute(#1:23:45 PM#)後,其值為何?
12(  45  )執行VB的內建函數Second(#1:23:45 PM#)後,其值為何?