013
輸入平面上兩個點,求直線方程式
輸入兩點座標,(x1, y1), (x2, y2)
輸出 y = mx + b(其中,m=(y1-y2)/(x1-x2)、b = (x2y1-x1y2)/(x2-x1))
輸入說明:
輸入兩行x,y分別代表兩點座標 (x1, y1), (x2, y2),其中x1、x2、y1、y2皆為整數
x,y 之間以一個逗號區隔
輸出說明:
輸出直線方程式y=mx+b
輸入輸出注意事項:
1.無需考慮斜率不存在的直線方程式(垂直於x軸的直線方程式)
2.若斜率為0(垂直於y軸的直線方程式),則輸出y=b (詳見範例測資1、2)
3.若直線方程式通過原點,則輸出y=mx (詳見範例測資13~16)
4.若m為正數,則無須輸出正號,若為負數,則需輸出負號,負號置於m最前方
5.若m為正負1,則無需輸出1的部分 (詳見範例測資13、14)
6.若m或b為整數,皆直接輸出整數
7.若m或b為分數,皆須以帶分數形式表示,且其真分數部分需化簡為最簡分數
8.若m或b為分數且取絕對值後大於1,則分數部分皆須加括號,例如:一又六分之一輸出為1(1/6)
9.請務必記得初始化變數
sample input 1:
-8,0
13,0
sample output 1:
y=0
sample input 2:
17,-8
-7,-8
sample output 2:
y=-8
sample input 3:
0,2
1,7
sample output 3:
y=5x+2
sample input 4:
1,-10
-2,11
sample output 4:
y=-7x-3
sample input 5:
1,1
6,4
sample output 5:
y=3/5x+2/5
sample input 6:
12,1
5,-1
sample output 6:
y=2/7x-2(3/7)
sample input 7:
6,-5
-4,3
sample output 7:
y=-4/5x-1/5
sample input 8:
1,2
-5,7
sample output 8:
y=-5/6x+2(5/6)
sample input 9:
1,8
-3,-11
sample output 9:
y=4(3/4)x+3(1/4)
sample input 10:
9,1
-18,-41
sample output 10:
y=1(5/9)x-13
sample input 11:
4,-9
-5,6
sample output 11:
y=-1(2/3)x-2(1/3)
sample input 12:
7,-12
-7,20
sample output 12:
y=-2(2/7)x+4
sample input 13:
8,8
-10,-10
sample output 13:
y=x
sample input 14:
-10,10
8,-8
sample output 14:
y=-x
sample input 15:
9,-5
-18,10
sample output 15:
y=-5/9x
sample input 16:
4,-14
-6,21
sample output 16:
y=-3(1/2)x