Problem:
Score : 200 points

Problem Statement

Find the number of palindromic numbers among the integers between A and B (inclusive).
Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.

Constraints

10000 \leq A \leq B \leq 99999

All input values are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the number of palindromic numbers among the integers between A and B (inclusive).

Sample Input 1

11009 11332

Sample Output 1

4

There are four integers that satisfy the conditions: 11011, 11111, 11211 and 11311.

Sample Input 2

31415 92653

Sample Output 2

612

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <cmath>
using namespace std;

int reverse_int(int n) {
	int logn = log10(n) + 1;
	int ans = 0;
	for (int i = 0; i < logn; i++) {
		ans = ans * 10 + n % 10;
		n /= 10;
	}
	return ans;
}

int main() {
	int A, B;
	cin >> A >> B;
	int logA = log10(A)+1;
	int logB = log10(B)+1;
	int a = A;
	int b = B;
	for (int i = 0; i < logA / 2; i++) a /= 10;
	for (int i = 0; i < logB / 2; i++) b /= 10;
	int aa = a;
	int bb = b;
	for (int i = 0; i < logA / 2; i++) aa *= 10;
	for (int i = 0; i < logB / 2; i++) bb *= 10;
	if (logA % 2 == 0) aa += reverse_int(a);
	else aa += reverse_int(a / 10);
	if (logB % 2 == 0) bb += reverse_int(b);
	else bb += reverse_int(b / 10);
	if (aa < A) a++;
	if (bb > B) b--;
	cout << a << " " << b << "\n";
	cout << b - a + 1;

}