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

Обсуждение задачи 1345. HTML

WA#9 C# Help (or other high level languages)
Послано Zergatul 7 мар 2021 07:43
I spent 5+ hours trying to understand why I am having WA#9.
DON'T use high level classes/methods like Console.Write/StreamReader/StreamWriter. Process input and send to output as raw bytes. I didn't find what was the issue (I am already tired with this shit), but I suppose StreamWriter or StreamReader can mess up with \r \n characters in some cases.

Here is code example for WA#9. I use Console.OpenStandardInput(0) as input, and Console.OpenStandardOutput(0) as output.


private static void SolveStateMachine(Stream input, Stream output)
{
    using var writer = new StreamWriter(output, Encoding.ASCII, 1024);

    void Write(char ch)
    {
        writer.Write(ch);
    }

    void WriteS(string str)
    {
        writer.Write(str);
    }

    ...
}

When I change about code to below, I am getting AC:

private static void SolveStateMachine(Stream input, Stream output)
{
    void Write(char ch)
    {
        byte[] buffer = new byte[1];
        buffer[0] = (byte)ch;
        output.Write(buffer, 0, 1);
    }

    void WriteS(string str)
    {
        byte[] buffer = Encoding.ASCII.GetBytes(str);
        output.Write(buffer, 0, buffer.Length);
    }

    ...
}
Re: WA#9 C# Help (or other high level languages)
Послано Zergatul 9 мар 2021 18:47
I got it. Test#9 is about characters with code >= 128. I was using Encoding.ASCII in C#, which causes replacing of all such characters with '?'. If your high level classes use UTF-8 encoding by default, you will also have problems.