Question: 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

1 Expert Approved Answer
Step: 1 Unlock

C CODE include include int compresschar word char comp int l1 strlenword int l2 strlencomp int i j0 ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Algorithms Questions!