|
|
вернуться в форумAC on C but Runtime error on C# Послано Semm 16 фев 2015 19:47 Hi, I've solved the problem easily on C, but can't solve it on C# (almost the same code), getting Runtime Error on #2. Can someone point out what's wrong in my code? using System; namespace Application { class MainClass { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] pos = new int[3]; for(int i=0; i<n; i++) { string[] s = Console.ReadLine().Split(' '); int ind = s[0][0] - 'X'; pos[ind] += int.Parse(s[1]); }
while(true) { if(pos[0] * pos[2] > 0) { int sign = pos[0] / Math.Abs(pos[0]); int min = Math.Min(Math.Abs(pos[0]), Math.Abs(pos[2])); pos[0] -= sign * min; pos[1] += sign * min; pos[2] -= sign * min; } else if(pos[0] * pos[1] < 0) { int sign = pos[0] / Math.Abs(pos[0]); int min = Math.Min(Math.Abs(pos[0]), Math.Abs(pos[1])); pos[0] -= sign * min; pos[1] += sign * min; pos[2] -= sign * min; } else if(pos[1] * pos[2] < 0) { int sign = pos[2] / Math.Abs(pos[2]); int min = Math.Min(Math.Abs(pos[1]), Math.Abs(pos[2])); pos[0] -= sign * min; pos[1] += sign * min; pos[2] -= sign * min; } else { break; } } int nOfDir = 0; if(pos[0] != 0) nOfDir++; if(pos[1] != 0) nOfDir++; if(pos[2] != 0) nOfDir++; Console.WriteLine(nOfDir); if(pos[0] != 0) Console.WriteLine("X " + (-pos[0]).ToString()); if(pos[1] != 0) Console.WriteLine("Y " + (-pos[1]).ToString()); if(pos[2] != 0) Console.WriteLine("Z " + (-pos[2]).ToString()); } } } Re: AC on C but Runtime error on C# To get AC instead of Console.ReadLine() I used Console.In.ReadToEnd().Split(new char[] { ' ', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries) |
|
|