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 wrong answer ?
Posted by touchinginfinity 28 Aug 2012 05:06
Hi
I am new to forum. I just tried Reverse Root problem and had judgement result as "wrong answer". Below is my code .. just wondering what is wrong with it. Because I ran it on Visual Studio and it seems to give right numbers.

Many Thanks
-----------------------------------------


#include <iostream>
#include <iomanip>
#include <cmath>
int main(){
    double arr[65536];
    int i = 0;
    int value = 0;
    while(std::cin >> value){
        arr[i++] = sqrt(static_cast<double> (value));
    }
    std::cout<<std::setprecision(4)<<std::fixed;
    while(i--)
        std::cout << arr[i] << std::endl;
}
Re: Why wrong answer ?
Posted by alex 4 Nov 2012 15:45
for example,

std::cout << std::setprecision(4) << sqrt(641234.123) << std::endl

gives result 800.8.

Presicion isn't in it's natural state.
Re: Why wrong answer ?
Posted by Song 12 Nov 2012 20:37
std::cout << std::setiosflags(ios::fixed) << std::setprecision(4) << your_number << std::endl

It is important to set ios::fixed flag.

And 2^32 -1 is smaller than 10^18, so an int cannot hold a larger number from input.

Edited by author 12.11.2012 20:39