ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1345. HTML

WA#9 C# Help (or other high level languages)
Posted by Zergatul 7 Mar 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)
Posted by Zergatul 9 Mar 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.