ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1140. Случай на болоте

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#
Послано kasarino 30 июл 2016 19:32
To get AC instead of Console.ReadLine() I used
Console.In.ReadToEnd().Split(new char[] { ' ', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)