TORONTO KIDS COMPUTER CLUB | Markham Saturday 15:30 Python Homework 20.03.07.
17196
post-template-default,single,single-post,postid-17196,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.8.0,vc_responsive

Markham Saturday 15:30 Python Homework 20.03.07.

12 Mar Markham Saturday 15:30 Python Homework 20.03.07.

Question:
You have come up with the following compression technique: for each symbol, write down the number of times it appears consecutively, followed by the symbol itself. This compression technique is called run-length encoding.

Given a sequence of characters, write a program to encode them in this format: The encoding of a line will be a sequence of pairs, separated by a space, where each pair is an integer (representing the number of times the character appears consecutively) followed by a space, followed by the character.

Sample Input 1:
+++===!!!!

Output for Sample Input 1:
3 + 3 = 4 !

Explanation of Output for Sample Input
To see how the first message (on the second line of input) is encoded, notice that there are 3 + symbols, followed by 3 = symbols, followed by 4 ! symbols.


Sample Input 2:
777777……TTTTTTTTTTTT

Output for Sample Input 2:
6 7 6 . 12 T

No Comments

Sorry, the comment form is closed at this time.