Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this problem, you have to make a compress function which take a word and compress it. compress function returns the 1 if the compression

In this problem, you have to make a compress function which take a word and compress it. compress function returns the 1 if the compression is successful(that is, the compressed word length is shorter than the original word length), and returns the 0 if the compression is fail(that is, the compressed word length is longer than the original word length or same as the original word length)

Goal : Make the function “compress”

• compress function has 2 arguments.

• Compression succeed if the comp length is shorter than word length. (If the comp length is same as the word length, then the compression is failed).

• If compression succeed, return 1, else, return 0.

• After calling compress function, the comp contains the compressed string which is shown in left figures.

Testcases condition

• The word contains alphabet letter only.

• word maximum length : 50

• Maximum consecutive letter length : 9

Examples

input :

aaaabbbccd

output :

Original word length : 10 | original word : aaaabbbccd

Compressed word length : 8 | compressed word : a4b3c2d1

Compression Success!

input :

zZzZzZzZ

output :

Original word length : 8 | original word : zZzZzZzZ

Compressed word length : 16 | compressed word : z1Z1z1Z1z1Z1z1Z1

Compression Failed!

Code(You only need to fill in "/* Fill the code */" part.)

#include
#include

/* Fill the code */

int main() {
char word[51], comp[101];
gets(word); // there is no testcase which exceed the length 50

int success = compress(word, comp);

printf("Original word length : %-4d | ", strlen(word));
printf("original word : %s", word);
printf("Compressed word length : %-4d | ", strlen(comp));
printf("compressed word : %s", comp);

if(success)
printf("Compression Success!");
else
printf("Compression Failed!");

return 0;
}

/* Fill the Code */

Step by Step Solution

There are 3 Steps involved in it

Step: 1

C CODE include include int compresschar word char comp int l1 strlenword int l2 strlencomp int i j0 ... 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

Intermediate Microeconomics

Authors: Hal R. Varian

9th edition

978-0393123975, 393123979, 393123960, 978-0393919677, 393919676, 978-0393123968

More Books

Students also viewed these Algorithms questions

Question

Contact person at the organization

Answered: 1 week ago