Question: Given n positive integers over multiple lines, where n is provided in the first line, print the run - length encoding sequence for each number
Given positive integers over multiple lines, where is provided in the first line, print the runlength encoding sequence for each number on separate lines. Runlength encoding represents how many times a digit is repeated consecutively.
For each number, every two values in the output represent the count of consecutive digits followed by the digit itself.
Input
The first line contains an integer representing the number of integers.
The next lines each contain one integer.
Output
For each of the n integers, print the runlength encoded sequence on a new line. Each line contains pairs of numbers where the first number in each pair is the count of consecutive digits, followed by the digit itself.
Example
For example, given the following input:
The output should be:
Explanation
times times times and time
times
times times times
time time time time time time
The below code is written by me i am getting the correct output but i am not able to print it in correct format
Test Case
# Write your code here
# Take the input from standard input using input
# and print the output according to the problem
# Write your code here
nintinput
integerlist
for i in rangen:
integerlist.appendstrinput
count
currentchar
for j in rangelenintegerlist:
for k in strintegerlistj:
ifkcurrentchar:
ifcurrentchar!:
printcountcurrentchar,end
count
currentchark
else:
currentchark
else:
count
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
