题目要求统计从m到n 的数字当中,0出现了几次。比如 99-101: 99 100 101 这里0 出现了3次
#include <cstdio>
#include <iostream>
#include <string.h>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define sfint(x) scanf("%d",&x)
#define sfint2(x,y) scanf("%d%d",&x,&y)
#define sfint3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define sfstr(c) scanf("%s",c)
#define sfdl(x) scanf("%lf",&x)
#define sfch(c) scanf("%d",&c)
#define pfint(x) printf("%d\n",x)
#define fr(i,s,n) for(int i=s;i<n;++i)
#define _fr(i,n,s) for(int i=n-1;i>=s;--i)
#define cl(a) memset(a,0,sizeof(a))
void count_digit(ll x,ll times,ll ans[]){
if (x<=0) return ;
ll a = x/10,b = x%10;
fr(i , 0 ,10) ans[i] += a*times;
fr(i , 1, b+1) ans[i] += times;
count_digit(a-1,times*10,ans);
while(a) ans[a%10] += (b+1)*times,a/=10;
}
ll ansa[10],ansb[10];
ll a,b;
int main(){
while(1){
scanf("%lld%lld",&a,&b);cl(ansa);cl(ansb);
if (a== -1 && b == -1) break;
if (a>0) a--;else ansb[0]++;
count_digit(a,1,ansa);
count_digit(b,1,ansb);
printf("%lld\n",ansb[0]-ansa[0]);
}
return 0;
}