You don't need to worry about outputing exactly the same as the sample
in the case of floating point.  As they say, if the number you print
out is within 1E-5 of what is expected, then it is considered
correct.  In fact you only need one of absolute or relative
difference, so if the number is really large you get more leeway.

Assuming your algorithm is correct, you can just output the number
with at least as many decimals as required, and printing out more
won't hurt.  I usually use 6, but 8 or even 10 would be okay.  One of
my solutions for problem C was even giving a negative 0 ("-0.000000")
but that was judged okay as well.

In short, pretty-printing floats is something you don't need to worry
about for GCJ (unless the problem is specifically about that, of
course).

Some problems don't state it, so from the FAQ:

Two floating point numbers are considered equal if their absolute or
relative difference is smaller than 1e-6

(unless otherwise stated, so in this case it was 1e-5).



On Apr 28, 6:26 pm, Carlos Guia <[email protected]> wrote:
> Use more than 5 and you're safe. Something like %.7f that way you would get
> a bunch 0s and sometimes some low order decimals. But the important thing
> is that the difference is less than 1e-5.
>
> Carlos Guia
> On Apr 28, 2012 4:43 PM, "Eric Kulcyk" <[email protected]> wrote:
>
>
>
>
>
>
>
> > Hello,
>
> > I had a partial solution for C coded up, however I wasn't sure how to
> > format the output correctly.  The problem says the answer for be correct to
> > 1E-5, but the sample output is "1.4"
> > When I use %.5f or %f, it does 1.40000.  I can get it to print 1.4 with
> > %.2g, however 1.45 outputs as 1.5 when using %.2g.  I tried to code a
> > solution that detected how many digits were in the solution, but it failed
> > for 120.000000000025 (it output 1.2e+02).
>
> > What's the correct way to do this?
> > BTW, using printf in java using eclipse.
>
> > Thanks,
> > Eric
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Code Jam" group.
> > To view this discussion on the web visit
> >https://groups.google.com/d/msg/google-code/-/colHK14rDqUJ.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group at
> >http://groups.google.com/group/google-code?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en.

Reply via email to