Bicolor numbers T80784


Statement
 

pdf   zip   main.cc

thehtml

We define a bicolor number as a natural number n with only two different digits that are repeated in two blocks (or "colors"). More formally, the sequence of digits of n is d1d2dke1e2el, where d and e are the two digits and, de, k > 0 and l > 0.

Examples of bicolor numbers: 7722, 44111, 666699, 277, and 45.
Examples of number which are not bicolor: 121, 113311, 7878, 1234, 7, 99910.

Implement a function is_bicolor that receives a natural number and determines if it is bicolor. The function receives a number n > 0 and returns true if it is bicolor and false otherwise.

The function header must be exactly:

/**
* @pre n >= 0
* @post returns true if n is bicolor, false otherwise
*/
bool is_bicolor(int n);

Observation

You only need to submit the requested function; the main program will be ignored.

Sample session
is_bicolor(0) -> false
is_bicolor(11) -> false
is_bicolor(45) -> true
is_bicolor(123) -> false
is_bicolor(112) -> true
is_bicolor(555) -> false
is_bicolor(1333) -> true
Information
Author
PRO1
Language
English
Translator
Original language
Catalan
Other languages
Catalan Spanish
Official solutions
C++
User solutions
C++