Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am taking a C programming class. I was wondering if you can help me with this question. You are pleasantly minding your own business

I am taking a C programming class. I was wondering if you can help me with this question. You are pleasantly minding your own business when your roommate suddenly asks you: Say, roommate, I have this sequence 1, 11, 21, 1211, 111221, .... What say you to find the next integer? After beating your brain for twenty minutes in a feeble attempt to find the pattern, it is revealed to you: given element (say) i3 = 21, the next element is formed from the phrase one 2, one 1. In general, in+1 is formed by reading in left-to-right as a string of digits and, for each run of n instances of digit d, append n followed by d to the output digit-string. For example, 114421 contains two 1s, two 4s, one 2, and one 1; the next integer in the sequence would be 21241211. Eager to put your programming prowess to use, you set about formalizing this transformation in a small utility program. The program should take (read from a file) a count n on one line, followed by n integers; for each of the n integers, it should output the integer that comes after n in the sequence.

Sample Input 5 // five integers follow

21

114421

5555555555

123456

1

Sample Output

1211

21241211

105

111213141516

11

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_2

Step: 3

blur-text-image_step3

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

More Books

Students also viewed these Databases questions