ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1001. Reverse Root

Why?
Posted by [МУПОЧ "Дубна"] Jester 4 Jan 2010 18:06
Why this
#include <math.h>
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

int main()
{
    vector<double> numbers;
    double number = 0;
    while(cin >> number){
        numbers.push_back(number);
    }

    for(int i = numbers.size() - 1; i >= 0 ; i--){
        cout<<setprecision(5)<<sqrt(numbers[i])<<'\n';
    }

    return 0;
}

is wrong and this

//...
printf("%.4lf\n", sqrt(numbers[i]));
//...

is write? I don't understand. Both ways are correct...
Re: Why?
Posted by tiancaihb 4 Jan 2010 18:33
I don't know C++ a lot, but I think setprecision(5) means at most 5 digits. So use this instead and be happy:
cout<<setprecision(5)<<setiosflags(ios::fixed)<<sqrt(numbers[i])<<'\n';
in which setiosflags(ios::fixed) means there must be 5 digits, filling with zero, which will satisfy the judge.

Edited by author 04.01.2010 18:41

Edited by author 04.01.2010 18:42