|
|
вернуться в форумWhy Crash? 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? 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? and hey.... what is this??? "Console.Write(String.Format("{0:f2}", l).Replace(',', '.'));" ???? write just: Console.Write("{0:F2}", l); Re: Why Crash? Thanks for your replay. The problem was in this F***ing Replace.. =) |
|
|