Problem Statement
Class name: MirrorImage
Method name: count
Parameters: int
Returns: int
Implement a class MirrorImage, which contains a method count. count takes an
integer as a parameter and returns the number of nonnegative integral
palindromes less than or equal to the integer. A palindrome is any number that
reads the same forward or backward. Any single digit is a palindrome.
The method signature is (be sure your method is public):
int count (int x);
TopCoder will ensure the following:
*x must be between 0 and 100000, inclusive.
Note:
-Leading zeroes do not count, 010 is not a palindrome.
-However 0 (zero) IS a palindrome.
-Palindromes have the same values when the order of their digits are reversed.
1234 is not a palindrome because it does not equal 4321. 12321 is a palindrome
because it equals its 12321.
Examples:
-If a=4, then the palindromes less than or equal to 4 are {0,1,2,3,4}, so the
method returns 5.
-If a=23, then the palindromes less than or equal to 23 are
{0,1,2,3,4,5,6,7,8,9,11,22}, so the method returns 12.
-If a=143, then the palindromes less than or equal to 143 are
{0,1,2,3,4,5,6,7,8,9,11,22,33,44,55,66,77,88,99,101,111,121,131,141}, so the
method returns 24.
Definition
- Class:
- MirrorImage
- Method:
- count
- Parameters:
- int
- Returns:
- int
- Method signature:
- int count(int param0)
- (be sure your method is public)
Constraints
Examples
No public sample cases were explicitly marked for this problem in the original data.