Function to fatten numbers X50141


Statement
 

pdf   zip   main.cc

html

In this problem, given any natural number x with n digits x1xn, we say that y = y1yn is the result of fattening x if, for every i between 1 and n, yi = max{x1, …, xi}. For instance, if we fatten 7 we get 7, if we fatten 32064781 we get 33366788, and if we fatten 9000000 we get 9999999.

Write a function

int fatten(int x);

to return the result of fattening x.

You cannot use vectors in the code. We suggest to think of a recursive solution. You may implement and use auxiliar procedures.

Your program should follow a right programming style. You should include the appropriate comments.

Precondition

It holds 0 < x < 109.

Observation You only need to submit the required procedure; your main program will be ignored.

Public test cases
  • Input/Output

    fatten(7) → 7
    fatten(32064781) → 33366788
    fatten(9000000) → 9999999
  • Information
    Author
    Jordi Cortadella
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan Spanish
    Official solutions
    Unknown. This problem is being checked.
    User solutions
    C++