#54198: C++ 求救


hch980506@gmail.com (申有娜我老婆)


#2: 15% WA (line:1)

您的答案為: 0.50
正確答案為: 0.49


CODE:

#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
    string input;
    while (cin >> input) {
        double ans = stod(input);
        ans = round((ans * 100)) / 100;
        if (fabs(ans) < 0.0005) {
            ans = 0;
        }
        cout << fixed << setprecision(2) << ans;
        cout << '\n';
    }
}
#54199: Re: C++ 求救


leeguanhan0909@gmail.com (李冠翰)


#2: 15% WA (line:1)

您的答案為: 0.50
正確答案為: 0.49


CODE:

#include
#include
#include
using namespace std;
int main() {
    string input;
    while (cin >> input) {
        double ans = stod(input);
        ans = round((ans * 100)) / 100;
        if (fabs(ans) < 0.0005) {
            ans = 0;
        }
        cout << fixed << setprecision(2) << ans;
        cout << '\n';
    }
}


小數有100位數,double精度不夠