M3P12 : 103模P12 解二元一次方程式
參考程式碼
Function
M3p12(ByVal s As String) As String
Dim
dt() = s.Split(",") '讀一列依 「,」分成6個字串
Dim a
As Integer = dt(0), b As Integer = dt(1)
Dim c
As Integer = dt(2), d As Integer = dt(3)
Dim e
As Integer = dt(4), f As Integer = dt(5)
'rem 聯立式(1)ax+by=c ,(1)式*e - (2)式*b 得(ae-db)x
= (ce-fb)
'rem 聯立式(2)dx+ey=f ,(1)式*d - (2)式*a 得(bd-ea)y
= (cd-fa)
Dim x
As Integer = (c * e - f * b) / (a * e - d * b)
Dim y
As Integer = (c * d - f * a) / (b * d - e * a)
Return
x & "," & y
End
Function
----------------------
in1.txt
----------------------
2
0,2,20,1,0,10
9,5,17,33,6,-24
----------------------
in2.txt
----------------------
2
2,5,2,1,2,7
2,5,95,-10,2,-16
----------------------
out.txt
----------------------
10,10
-2,7
31,-12
5,17