|
|
вернуться в форумTest 5 failure - Please help!. 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!. 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!. You are correct, but what is the difference between the two thing? |
|
|