TF. 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.
Example
Input
2 47
Output
12
Note
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.
code
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 510,INF=0x3f3f3f3f,mod=1e9+7;
typedef pair<int,int> PII;
int T=1;
int f(int x){
if(x<10) return x;
string str=to_string(x);
if(str[0]>str[str.size()-1]) return x/10+8;
else return x/10+9;
}
void solve(){
int n,m;
cin>>n>>m;
cout<<f(m)-f(n-1)<<endl;
}
signed main(){
// cin>>T;
while(T--){
solve();
}
return 0;
}
标签:integers,Little,return,int,Interval,Elephant,pair
From: https://blog.csdn.net/2303_79062963/article/details/143530960