Question
You are pleasantly minding your own business when your roommate suddenly asks you: Say, room- mate, I have this sequence 1, 11, 21, 1211, 111221,
You are pleasantly minding your own business when your roommate suddenly asks you: Say, room- mate, I have this sequence 1, 11, 21, 1211, 111221, .... What say you to finding 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started