14284 - More Polymorphic Codec Classes   

Description

This is a partial judge problem.
You're asked to implement encode function in several class that inherit the base class "Codec".

class Codec {
public:
    Codec(std::string s): code_str{s} {}
    virtual ~Codec() {}
    virtual void encode() = 0;
    void show(std::ostream& os) const { 
        os << code_str;
    }
protected:
    std::string code_str;
};

There are three types of Codec.

The first one is the AB Codec, it should turn all the 'A' to 'B', and all the 'B' to 'A'. ('A', 'B' are upper case english character)

The second one is the Comma Codec, it should add a comma ',' every 5 characters. For example, the string "HELLOWORLD" will turn into "HELLO,WORLD," after encoding. 

The third one is the Numeric RLE Codec which enhances traditional encoding methods. This codec involves a multi-step transformation process:

  1. Alphabet to Numeric: Each letter from 'A' to 'Z' is converted to a corresponding numeric code from '00' to '25'.
  2. Numeric to Alphabetic: Each digit from '0' to '9' is then transformed into a corresponding lower case letter from 'a' to 'j'.
  3. Run-Length Encoding: Finally, we apply run-length encoding to the resulting string.

To encode the string "AAAAB" using the Number RLE Codec, follow these steps:

  1. Convert 'A' to '00' and 'B' to '01', turning "AAAAB" into "0000000001".
  2. Replace '0' with 'a' and '1' with 'b', resulting in "aaaaaaaab".
  3. Apply run-length encoding to get "9ab".

What is run-length encoding? : Count the number of consecutive repeated characters in a string, and replace the repeated characters by the count and a single instance of the character. Note that we do not need to encode runs of length one or two, since ‘2B’ and ‘1C’ are not shorter than ‘BB’ and ‘C’.


TODOs: In ‘function.cpp’, please implement the function encode() in class "ABCodec", "CommaCodec", and "NumRLECodec".

For more information, you should refer to the main.cpp and function.h.

Notes: When you submit, you need to implement all three encode function (you can left it empty inside) or you will get a compile error.

Input

The first line contains a string, which can be ‘AB’, ‘Comma’ or ‘NumRLE’.
The second line contains a string with only uppercase letters, representing the string to be encoded.

Constraints:
Testcases 1~4: The first line would be ‘AB’.
Testcases 5~8: The first line would be ‘Comma’.
Testcases 9~10: The first line would be ‘NumRLE’.

Output

Output the encoded string.

Please refer to the sample output for details.

Sample Input  Download

Sample Output  Download

Partial Judge Code

14284.cpp

Partial Judge Header

14284.h

Tags




Discuss