在數列中有等差數列以及等比數列,已知道數列的前四項,請判斷出此數列是等差或者等比數列,並求出公差或等比。
輸入說明:
第一行是數列的數目t(0<= t <=10) 。以下每行均包含四個以空白格開的整數,表示數列的前四項。數列的前四項均為不大於10000的自然數,等比數列的比值也是自然樹。
輸出說明:
對數列的每個數列,輸出兩個欄位,欄位與欄位之間以一個空白隔開,若是等差數列則第一欄輸出A,若為等比數列則第一欄輸出G;第二欄則根據數列的判斷結果,輸出其公差或是等比。
輸入範例:
2
2 4 6 8
2 4 8 16
輸出範例:
A 2
G 2
Private Sub Form_Load()
回覆刪除Dim w, x, y, z As Integer
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, n
For i = 1 To n
Input #1, w, x, y, z
If x - w = z - y Then
Print #2, "A" & z - y
Else
Print #2, "G" & z / y
End If
Next
Close
Close
End
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 i = 1 To n
Input #1, a, b, c, d
If (d / c) = (c / b) Then
Print #2, "G" & c / b
Else
Print #2, "A" & c - b
End If
Next i
Close
Close
End
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 i = 1 To n
Input #1, v, w, x, y
If (w + y) / 2 = x Then Print #2, "A"; w - v
If w / v = x / w Then Print #2, "G"; w / v
Next i
Close #2
Close #1
End
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 i = 1 To Val(n)
Input #1, a, b, c, d
If Val(b) - Val(a) = Val(d) - Val(c) Then
Print #2, "A" & (Val(b) - Val(a))
ElseIf Val(b) / Val(a) = Val(d) / Val(c) Then
Print #2, "G " & (Val(b) / Val(a))
End If
Next i
Close #2
Close #1
End