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 1307. Archiver

Advices after almost a week spent on this task.
Posted by prituladima 14 Dec 2021 16:37
0. I wanted to implement universal approach with Huffman coding + compressing binary code to 64 base code. Not just eng text property (I was upset, because for so interesting task so stupid solution works).

1. I'm Java developer, and I afraid that Java consume too much memory even for input.
So I have to rewrite all to cpp.

2. Thinks that costs me a lot of time.
Input in cpp. (If you can explain what is wrong. please do )
WRONG
inputData = "";
std::string line = "";
while (std::getline(std::cin, line)) {
    inputData += line;
    //inputData.push_back('\r');//todo maybe we need \r\n
    inputData.push_back('\n');
}


CORRECT
inputData = "";
int c;
while ((c = getchar()) != EOF)
    inputData.push_back((char)c);

3. Escaping characters to produce cpp code:
std::string escape(char ch) {
    switch (ch) {
        case '\'':
            return "\\'";
        case '\"':
            return "\\\"";
        case '\\':
            return "\\\\";
        case '\b':
            return "\\b";
        case '\f':
            return "\\f";
        case '\n':
            return "\\n";
        case '\r':
            return "\\r";
        case '\t':
            return "\\t";
        default:
            return {ch};
    }
}

I finally got AC. So I wish you good luck with this problem and thank to author so interesting problem.