Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions

Question

What are the functions of top management?

Answered: 1 week ago

Question

Bring out the limitations of planning.

Answered: 1 week ago

Question

Why should a business be socially responsible?

Answered: 1 week ago

Question

Discuss the general principles of management given by Henri Fayol

Answered: 1 week ago

Question

7. Discuss the key features of the learning organization.

Answered: 1 week ago