计算区间内1的个数
#include <stdio.h>
int pow[10] = {1,10,100,1000,10000,100000,1000000,10000000,100000000};
int getNum(int n)
{
int byte = 0, sum = 0, temp = n;
if(n < 0)
{
return 0;
}
while(temp != 0)
{
if(temp%10 > 1)
{
sum += pow[byte];
}
else if(temp % 10 == 1)
{
sum += (n%pow[byte]+1);
}
sum += temp%10*byte*pow[byte-1];
byte++;
temp /= 10;
}
return sum;
}
int main()
{
int low, high;
while(scanf("%d%d", &low, &high) && (low+high))
{
if(low < high)
{
printf("%d\n", getNum(high)-getNum(low-1));
}
else
{
printf("%d\n", getNum(low)-getNum(high-1));
}
}
return 0;
}