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

Why Crash?
Posted by diejmon 5 Aug 2010 23:04
using System;
using System.Collections.Generic;

namespace Task_1020
{
    public class Program
    {
        private struct Point {
            public double X { get; set; }
            public double Y { get; set; }
        }
        public static void Main() {
            Point nR = Read();
            double n = nR.X;
            double r = nR.Y;

            var points = new List<Point>((int)n);
            for (int i = 0; i < n; i++) {
                points.Add(Read());
            }

            double l = 2*Math.PI*r;

            if (n == 1) {
                Console.Write(String.Format("{0:f2}", l).Replace(',', '.'));
            }
            else {
                l += ComputeLength(points[0], points[(int) (n - 1)]);

                for (int i = 0; i < n - 1; i++) {
                    l += ComputeLength(points[i], points[i + 1]);
                }
                Console.Write(String.Format("{0:f2}", l).Replace(',', '.'));
            }

        }

        private static double ComputeLength(Point p1, Point p2) {
            return Math.Sqrt(Math.Pow(p1.X - p2.X, 2)
                + Math.Pow(p1.Y - p2.Y, 2));
        }

        private static Point Read () {
            var twoNum = Console.ReadLine().Split(' ');
            twoNum[0] = twoNum[0].Replace('.', ',');
            twoNum[1] = twoNum[1].Replace('.', ',');
            return new Point {X = Double.Parse(twoNum[0]), Y = Double.Parse(twoNum[1])};
        }
    }
}
Re: Why Crash?
Posted by Andrew Hoffmann aka SKYDOS [Vladimir SU] 5 Aug 2010 23:09
OMG man!
What a F*** code!))

What for these things are: Replace(',', '.') ????

you can read two double vals:
double[] point = Console.ReadLine().Split().Select(s=> double.Parse(s)).ToArray();
x = point[0];
y = point[1];

try it!
Re: Why Crash?
Posted by Andrew Hoffmann aka SKYDOS [Vladimir SU] 5 Aug 2010 23:12
and hey....
what is this??? "Console.Write(String.Format("{0:f2}", l).Replace(',', '.'));"
????

write just: Console.Write("{0:F2}", l);
Re: Why Crash?
Posted by Andrew Hoffmann aka SKYDOS [Vladimir SU] 5 Aug 2010 23:16
Here is mine template for C#
http://paste.ubuntu.com/473617/
Re: Why Crash?
Posted by diejmon 5 Aug 2010 23:40
Thanks for your replay. The problem was in this F***ing Replace.. =)