题意:找出区间 [n,m] 中有多少个零
分析:从个位往最高位递推,令当前位为0,统计其余位置可能的变化
#include <cstdio>
#include <iostream>
#include <iostream>
#include <cstring>
using namespace std;
typedef long long int ll;
ll n, m ;
ll deal(ll x)
{
if( x < 0 )return 0;
ll res = 1 ;//此处注意 , + 1 防止 n 等于0的情况
ll div = 10 ;
while( x >= div )
{
ll a = x / div;
ll b = x % div;
ll c = x % ( div / 10 );
if( (b - c) % div == 0 ){//处理的当前位为0
res += (a-1)*(div/10) + c + 1;
}
else res += a*(div/10);
div *= 10;
}
return res;
}
int main()
{
while (cin >> n >> m && ( n >= 0 ))
{
cout << deal(m) - deal(n-1) << endl;
}
}