|
|
back to boardDiscussion of Problem 1020. RopeCrash 4: without Replace(...) Can anyone help me? This is my code wich has Crash on the 4th test: using System; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Collections; using System.Collections.Generic; using System.Text; using System.IO; using System.Globalization; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo; String[] str = Console.ReadLine().Split(new char[] { ' ', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries); int n = int.Parse(str[0], nfi); int r = int.Parse(str[1], nfi); double length = 0; if (n == 1) { length += r * Math.PI * 2; Console.Write(String.Format(nfi, "{0:F2}", length)); return; } double[][] mat = new double[n][]; for (int i = 0; i < n; i++) mat[i] = new double[2]; for (int i = 0; i < n; i++) { String[] str1 = Console.ReadLine().Split(new char[] { ' ', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries); mat[i][0] = Double.Parse(str1[0], nfi); mat[i][1] = Double.Parse(str1[1], nfi); } for (int i = 0; i < n; i++) { if (i == n - 1) { length += Math.Sqrt((mat[i][0] - mat[0][0]) * (mat[i][0] - mat[0][0]) + (mat[i][1] - mat[0][1]) * (mat[i][1] - mat[0][1])); break; } length += Math.Sqrt((mat[i][0] - mat[i + 1][0]) * (mat[i][0] - mat[i + 1][0]) + (mat[i][1] - mat[i + 1][1]) * (mat[i][1] - mat[i + 1][1])); } length += r * Math.PI * 2; Console.Write(String.Format(nfi, "{0:F2}", length)); } } } |
|
|