Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make sure to test for all possible test cases Your new cellphone plan charges you for every character you send from your phone. Since you

image text in transcribedimage text in transcribedMake sure to test for all possible test cases

Your new cellphone plan charges you for every character you send from your phone. Since you tend to send sequences of symbols in your messages, 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. More formally, a block is a substring of identical symbols that is as long as possible. A block will be represented in compressed form as the length of the block followed by the symbol in that block. The encoding of a string is the representation of each block in the string in the order in which they appear in the string. Given a sequence of characters, write a program to encode them in this format. Input Specification The first line of input will contain the number N, which is the number of lines that follow. The next N lines will contain at least one and at most 80 characters, none of which are spaces. Output Specification Output will be N lines. Line i of the output will be the encoding of the line i+1 of the input. The encoding of a line will be a sequence of pairs, separated by a space, where each is an integer (representing the number of times the character appears consecutively) followed by a space, followed by the character. Sample Input 4 +++=== !!!! 777777. . . TTTTTTTTTTTT (AABBC) 3.1415555 Output for Sample Input 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis In Microsoft Excel

Authors: Alex Holloway

1st Edition

B0CCCPKTTX, 979-8852388452

More Books

Students also viewed these Databases questions

Question

work settings of recent graduates;

Answered: 1 week ago

Question

7-16 Compare Web 2.0 and Web 3.0.

Answered: 1 week ago