codeforces 204A Little Elephant and Interval 美丽的区间转换



The Little Elephant very much loves sums on intervals.

This time he has a pair of integers l and r(l ≤ r). The Little Elephant has to find the number of such integers x(l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.

Help him and count the number of described numbers x for a given pair l and r.

Input

The single line contains a pair of integers l and r(1 ≤ l ≤ r ≤ 1018) — the boundaries of the interval.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

Output

On a single line print a single integer — the answer to the problem.

Sample Input

Input
2 47
Output
12
Input
47 1024
Output
98

Sample Output

Hint

In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.


题意就是说在给定区间(a,b)找到首末数字相同的个数;

思路就是转换一下:先求到前a个数里面有多少个,在找到前b个数里面有多少个,在把两个减法的结果

注意问题:用long long存,传递参数的时候long long的,就应为这个wa了好几次

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

long long f(long long x){
    long long ll = 0,ge;
    if(x < 10){
        return x;
    }
    ge = x % 10;
    ll = x / 10 + 9;
    while(x >= 10){
        x /= 10;
    }
    if(x > ge){
        ll--;
    }
    return ll;
}
int main(){
    long long  a,b;
    long long suma,sumb;
    while(~scanf("%I64d%I64d",&a,&b)){
        suma = f(a - 1);
        sumb = f(b);
        printf("%I64d\n",sumb - suma);
    }
    return 0;
}

这道题小小突破了正常的思维,正常的我们是按照从a到b找,但是这样会出现好多情况的讨论,巧妙的转换思路求的的结果,庆祝我学到的新知识,继续加油。


你可能感兴趣的:(codeforces 204A Little Elephant and Interval 美丽的区间转换)