Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please DO THE FOLLOWING PROMPT IN C## and ONLY C## Manytimes,certaindatafiletypescanconsistoflarge amounts of repeated data. For instance, images can have large runs of the same

Please DO THE FOLLOWING PROMPT IN C## and ONLY C## 

Manytimes,certaindatafiletypescanconsistoflarge amounts of repeated data. For instance, images can have large runs of the same color. This can be easily compressed using a technique called run length encoding. With run length encoding, large amounts of repeated data are stored as the repeated data and the number of times to repeat it.

CreateaclassRunLengthEncodethatcontainsthemethod encode which takes one argument: a String to be encoded as described below.

ThereturnvalueshouldbeaStringwhichhasbeenencoded with the following algorithm:

Ifanycharacterisrepeatedmorethan4times,theentire set of repeated characters should be replaced with a slash '/', followed by a 2-digit number which is the length of the set of characters, and the character. For example, "aaaaa" would be encoded as "/05a". Runs of 4 or less characters should not be replaced since performing the encoding would not decrease the length of the string.

Notes

Letters are case sensitive. For example "AaAaAa" cannot be encoded.

You may only encode repeats of a single character, repeats of multiple characters cannot be encoded. For example "ababababab" cannot be encoded as "/05ab".

Constraints

input will have between 0 and 50 characters, inclusive.

input will consist only of letters 'a' - 'z' and 'A' - 'Z',

digits '0' - '9', the space character, and the characters in the following string: "{}[]():;'+=.,". (quotes are for clarity only and cannot be in the input string)

Adopted from https://www2.cs.duke.edu/csed/newapt/runlengthencode.html 

Examples

a) "aaaaa"

a.Returns: "/05a" b. The example stated above.

b) "aaaa"

a. Returns: "aaaa" b. Remember not to encode runs of length 4 or less.

c) "abcabcabcabcabc"

Returns: "abcabcabcabcabc"

Do not encode repeated segments of more than one

character

d) "if(a){if(b){if(c){if(d){if(e){5 deeeeeeep}}}}}"

a. Returns: "if(a){if(b){if(c){if(d){if(e){5 d/07ep/05}" e) ""

a. Returns: ""

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_2

Step: 3

blur-text-image_3

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

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions

Question

33. If the pdf of a measurement error X is f(x) , show that

Answered: 1 week ago