#18978: 我測試過了 提交卻只有20%?


nick26268@g.ncu.edu.tw (ちょう可愛いのゆんゆん)


import sys
for x in sys.stdin:
x = x.split()
a = int(x[0])
b = int(x[1])
c = int(x[2])
s = (b ** 2) - (4 * a * c)

if s >0:
x1 = (-b+s**0.5)/2*a
x2 = (-b-s**0.5)/2*a
print("Two different roots x1="+str(int(x1)) +" , x2="+str(int(x2)))
elif s ==0:
x = (-b+s**0.5)/2*a
print("Two same roots x="+str(int(x)))
else:
print("No real root")
 
 
求幫忙看哪裡有問題
#18979: Re:我測試過了 提交卻只有20%?


inversion (「我們所認識的可符香是個像天使的好女孩」之葉林 *Cries...)


import sys
for x in sys.stdin:
x = x.split()
a = int(x[0])
b = int(x[1])
c = int(x[2])
s = (b ** 2) - (4 * a * c)

if s >0:
x1 = (-b+s**0.5)/2*a
x2 = (-b-s**0.5)/2*a
print("Two different roots x1="+str(int(x1)) +" , x2="+str(int(x2)))
elif s ==0:
x = (-b+s**0.5)/2*a
print("Two same roots x="+str(int(x)))
else:
print("No real root")
 
 
求幫忙看哪裡有問題


藍色部分應為「/ (2 * a)」而非「/ 2 * a」。

因為是要除以 2a 而不是 除以 2 再乘以 a ,您原本的寫法會變成後者的結果。(運算規則是:先乘除後加減,由左至右運算)

以上。希望有幫到您的忙。

 

#18983: Re:我測試過了 提交卻只有20%?


nick26268@g.ncu.edu.tw (ちょう可愛いのゆんゆん)


import sys
for x in sys.stdin:
x = x.split()
a = int(x[0])
b = int(x[1])
c = int(x[2])
s = (b ** 2) - (4 * a * c)

if s >0:
x1 = (-b+s**0.5)/2*a
x2 = (-b-s**0.5)/2*a
print("Two different roots x1="+str(int(x1)) +" , x2="+str(int(x2)))
elif s ==0:
x = (-b+s**0.5)/2*a
print("Two same roots x="+str(int(x)))
else:
print("No real root")
 
 
求幫忙看哪裡有問題


藍色部分應為「/ (2 * a)」而非「/ 2 * a」。

因為是要除以 2a 而不是 除以 2 再乘以 a ,您原本的寫法會變成後者的結果。(運算規則是:先乘除後加減,由左至右運算)

以上。希望有幫到您的忙。

 


謝謝學長指導!XD