We define a bicolor number as a natural number with only two different digits that are repeated in two blocks (or "colors"). More formally, the sequence of digits of is , where and are the two digits and, , and .
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
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);
You only need to submit the requested function; the main program will be ignored.
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