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:
To encode the string "AAAAB" using the Number RLE Codec, follow these steps:
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.
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 the encoded string.
Please refer to the sample output for details.