RLE (Run-Length Encoding) - 1 Point
In this age of more information and more speed, compression algorithms
are everywhere. You've just been hired to implement a fairly simple compression
algorithm known as Run Length Encoding. Run Length Encoding (RLE) replaces
sequences of the same character with the a number representing length of
the sequence and the character.
Ex. eeethbbbb (has 3-e's, 1-t, 1-h, and 4-b's) -so encodes to->
3eth4b
Note that for a run-length of 1, the 1 is not needed.
Each character is a number, letter, or one of the following:
/ \ . , ! ? ( ) &
If a single number is used then the '/' character is placed in front of
it. h6pp -> h/62p. If a single '/' is needed then
two slashes are used '//' thus 6/opp -> /6//o2p also
///5 -> 3//5 which should read a run of 3 of type '/' then
a single '/' of type '5'. Your job is to implement a program
that can both encode and decode RLE.
Input Format
Each sequence will consist of two lines.
The first line will say encode or decode, and the second line will hold
the information.
A -1 indicates the end of the sequence.
A double -1 indicates the end of all sequences.
The input file will be called jin04.txt.
Output Format
You should output the operation performed and the new information.
Example
Input
encode
fffff1ddf1eggggggggh/
-1
decode
/6//3op
-1
-1
Output
Encode: 5f/12df/1e8gh//
Decode: 6/ooop