Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.8 kB
2
Indexable
Never
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

bool check(string s)
{
    int n = s.length();
    for(int i=0;i<(n/2);i++)
    {
        if(s[i]!=s[n-i-1])
        {
            return 0;
        }
    }
    return 1;
}

int main()
{
    long long int l,r;
    while(cin>>l>>r)
    {
        long long int count=0;
        if(r<=10 && l<10)
		{
			cout<<r-1<<endl;
			continue;
		}
        if(l<10)
        {
			if(r <=100)
			{
				if(l<10)
				{
					count = 10-l;
					
				}
				r/=10;
				cout <<count+r-1;
				continue;
			}
            count = 10-l;
            l=11;
        }
        string s = to_string(l);
        string a = to_string(r);
        long long int b = s.length(),c=a.length();
        long long int q = pow(10,b-1);
        long long int y = pow(10,c-1);
        long long int h = l%q;
        long long int k = r%y;
        long long int v = l-h;
        long long int x = r-k;

        for(long long int i=v;i<x;i=k)
        {
             s = to_string(i);
             b = s.length();
            k = pow(10,b);
            if(k>x)
            {
                k = x;
            }
             if(b%2==0)
             {
                 b = (b/2)-1;
             }
            else
            {
                b = b/2;
            }
            c = s.length();
            int e = i/(pow(10,c-1));
            int t = k/(pow(10,c-1));
            y = pow(10,b);
            count+=(y*(t-e));
        }
        for(long long int i=k;i<=r;i++)
        {
            if(check(to_string(i)))
            {
                //cout<<i<<endl;
                count++;
            }
        }
        cout<<count<<endl;
       // cout<<count__<<endl;
    }
}