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

Help JAVA Program
Posted by Frank Rodriguez 2 Jan 2008 00:39
For some reason it wont read the input correctly, my arrays dont contain the right coordinates. Can anyone tell me why?


import java.util.*;
import java.io.*;

public class rope
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();
        int r = in.nextInt();

        double[] x = new double[n];
        double[] y = new double[n];

        double ans = 0.0;
        ans += 2*Math.PI*r;

        for (int i=0; i<n; i++)
        {
            x[i]=in.nextDouble();
            y[i]=in.nextDouble();
        }

        for (int i=0; i<n; i++)
        {
        ans+= Math.sqrt(Math.pow((x[i]-x[i==0 ? n-                1 : i-1]),2)+Math.pow((y[i]-y[i==0 ? n-                1:i-1]),2));
        }

        out.println(ans);
        out.flush();
    }
}
Re: Help JAVA Program
Posted by Ilya001(Java) 9 Mar 2008 13:41
 r is real.

Double r = in.nextDouble();
Re: Help JAVA Program
Posted by Van_Veber 5 Aug 2009 23:45
Code
=================================================================
import java.util.*;
import java.io.*;

public class t1020
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = in.nextInt();
        Double R = in.nextDouble();

        Double[] x = new Double[N];
        Double[] y = new Double[N];

        double len = 2 * Math.PI * R;

        for(int i = 0; i < N; i ++)
        {
            x[i] = in.nextDouble();
            y[i] = in.nextDouble();
        }

        for(int i = 0; i < N - 1; i ++)
            len += Math.sqrt(Math.pow((x[i] - x[i == 0 ? N - 1 : i - 1]), 2) + Math.pow((y[i] - y[i == 0 ? N - 1 : i - 1]), 2));

        out.println(len);
        out.flush();
    }
}
================================================================
Write:
================================================================
4 1.0
Exception in thread "main" java.util.InputMismatchException
    at java.util.Scanner.throwFor(Unknown Source)
    at java.util.Scanner.next(Unknown Source)
    at java.util.Scanner.nextDouble(Unknown Source)
    at t1020.main(t1020.java:12)
=================================================================
Why I can not read 1.0?!
4 1 --  Read correctly!!!
Re: Help JAVA Program
Posted by Fyodor Menshikov 7 Aug 2009 20:13
in.useLocale(Locale.US);