User input a string
e.g. STR = “AAAAGGGSWWWWWWJ”
Apply RLE and print the compressed string, “A4G3S1W6J1”
DECLARE Str : STRING
DECLARE Ch1, Ch2 : CHAR
DECLARE Counter : INTEGER
DECLARE Continuous : BOOL
OUTPUT “Please enter String to compress.”
INPUT Str
Repeated 1
For C 1 TO Length(Str) // C is Counter
Ch1 MID(Str, Counter, 1)
Ch2 MID(Str, Counter+1, 1)
IF Ch1 = Ch2 THEN
Repeated Repeated + 1
ELSE
OUTPUT Ch1 & Repeated // Print ch and its count on
same line
Repeated 1 // Reset C for the next ch
sequence
ENDIF
NEXT Counter
// Print the last character and its count on the same line
OUTPUT MID(Str, Length(Str), 1) & Repeated