Run Length Encoding --- ------ -------- Your task is to write a program named rle that performs a simple form of run-length encoding, as described by the rules below. - The input consists of letters ('a' through 'z', both uppercase and lowercase), digits, spaces, punctuation, and newline characters. The input is guaranteed to not contain any other characters. - Each line in the input is encoded separately. The newline at the end of each line is not encoded, but is passed directly to the output. There- fore, the input and the output have exactly the same number of lines, and each line in the output represents the encoding of one line of the input. - Any sequence of between 2 to 9 identical characters is encoded by two characters. The first character is the length of the sequence, represented by the ASCII codes '2' through '9'. The second character is the value of the repeated character. - Any sequence of characters that does not contain consecutive repetitions of any characters is represented by a '1' character followed by the sequence of characters, terminated with another '1'. If a '1' appears as part of the sequence, it is escaped with a '1'. Therefore, whenever a '1' appears in a sequence, two '1's must be output. For example, the input line "AAAAAABCCCC" would be represented by the following seven characters: '6' - The number of A's. 'A' - The character 'A'. '1' - A marker indicating the start of a sequence of characters that do not contain consecutively repeated characters. 'B' - The character 'B'. '1' - The end marker. '4' - The number of C's. 'C' - The character 'C'. The input line "12344" would be represented by the following eight characters: '1' - A '1' to indicate the start of a sequence of unrepeated characters '1' - A '1' that "escapes" the following '1', so that it is not interpreted as the end of the sequence. '1' - The escaped '1' '2' - The character '2'. '3' - The character '3'. '1' - The '1' that marks the end of the sequence. '2' - The number of 4's. '4' - The character '4'. Thus: Example Input: AAAAAABCCCC 12344 Corresponding Output: 6A1B14C 11123124 File: rle.txt Author: Dan Ellard Date: Sat Sep 7 10:24:09 EDT 2002 The authors have placed this file in the public domain; they make no warranty and accept no liability for this file. RCS Info (may not be true date or author): $Author: hc3 $ $Date: 2002/09/08 02:18:53 $ $RCSfile: rle.txt,v $ $Revision: 1.2 $