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

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!