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 1020. Rope

Test 5 failure - Please help!.
Posted by ElPsyCongroo 23 Jun 2014 04:27
My code below is failing at test 5. Please help me.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Cryptography1086
{
    public static void main( String[] args ) throws Exception
    {
        BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );

        StringTokenizer st = new StringTokenizer( br.readLine() );

        int numberOfNails = Integer.parseInt( st.nextToken() );

        double radiusOfNails = Double.parseDouble( st.nextToken() );

        double lengthOfRope = 2 * Math.PI * radiusOfNails;

        st = new StringTokenizer( br.readLine() );
        double x0 = Double.parseDouble( st.nextToken() );
        double y0 = Double.parseDouble( st.nextToken() );

        if( numberOfNails == 1 )
        {
            DecimalFormat df = new DecimalFormat( "#.00" );

            System.out.println( df.format( lengthOfRope ) );
            return;
        }

        double xStore = x0;
        double yStore = y0;

        double xK = 0;
        double yK = 0;

        for( int inx = 1 ; inx < numberOfNails; ++inx )
        {
            st = new StringTokenizer( br.readLine() );

            xK = Double.parseDouble( st.nextToken() );
            yK = Double.parseDouble( st.nextToken() );

            double dx = Math.pow( (xK - x0), 2 );
            double dy = Math.pow( (yK - y0), 2 );

            double dxy = Math.sqrt( dx + dy );

            lengthOfRope += dxy;

            x0 = xK;
            y0 = yK;
        }

        double d1 = Math.pow( (xK - xStore), 2 );
        double d2 = Math.pow( (yK - yStore), 2 );
        lengthOfRope += Math.sqrt( d1 + d2 );


        DecimalFormat df = new DecimalFormat( "#.00" );

        System.out.println( df.format( lengthOfRope ) );
    }
}
Re: Test 5 failure - Please help!.
Posted by ElPsyCongroo 28 Jun 2014 23:47
The problem was my usage of DecimalFormat df = new DecimalFormat( "#.00" );

It should have been something like this: DecimalFormat df = new DecimalFormat( "0.00" );

Note the '#' to '0' change.
Re: Test 5 failure - Please help!.
Posted by David Yin 19 Apr 2015 17:06
You are correct, but what is the difference between the two thing?