#21079: 為什麼改了變AC?


m923t917 (XDDDDXD)

學校 : 不指定學校
編號 : 119406
來源 : [1.164.61.253]
最後登入時間 :
2020-04-14 18:25:30
d051. 糟糕,我發燒了! -- 板橋高中教學題 | From: [1.164.65.214] | 發表日期 : 2020-04-08 17:08

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

float f;

while (cin >> f)

{

cout << fixed << setprecision(3) << (f-32)/1.8 << endl;

}

return 0;

}

用上面的程式碼 結果是NA:

#3: 10% WA (line:1)

您的答案為: 1193046471.111

 

正確答案為: 1193046452.778

 

後來改成..

 

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

double f;

while (cin >> f)

{

cout << fixed << setprecision(3) << (f-32)/1.8 << endl;

}

return 0;

}

把float換成double後,就AC了
不太能理解,希望有大神能解答~~

 
#21093: Re:為什麼改了變AC?


easylin0126@gmail.com (林榮翼)

學校 : 臺北市立成功高級中學
編號 : 89424
來源 : [140.114.207.162]
最後登入時間 :
2023-09-27 16:33:24
d051. 糟糕,我發燒了! -- 板橋高中教學題 | From: [27.52.63.89] | 發表日期 : 2020-04-10 10:36

#include

#include

using namespace std;

int main()

{

float f;

while (cin >> f)

{

cout << fixed << setprecision(3) << (f-32)/1.8 << endl;

}

return 0;

}

用上面的程式碼 結果是NA:

#3: 10% WA (line:1)

您的答案為: 1193046471.111

 

正確答案為: 1193046452.778

 

後來改成..

 

#include

#include

using namespace std;

int main()

{

double f;

while (cin >> f)

{

cout << fixed << setprecision(3) << (f-32)/1.8 << endl;

}

return 0;

}

把float換成double後,就AC了
不太能理解,希望有大神能解答~~

因為double的精度比較高,因此建議以後都用double取代float><


 
ZeroJudge Forum