1 10 44 497 346 542 0 0
2 185 40
十进制数中1的个数!
AC码:
#include<stdio.h> long long solve(long long x) { if(x<0) return 0; long long t=0,p=1,temp=x; while(x>0) { if(x%10==0) t+=x/10*p; else { if(x%10==1) { if(x==temp) t+=x/10*p+1; else t+=temp%p+1+x/10*p; } else t+=(x/10+1)*p; } x/=10; p*=10; } return t; } int main() { long long a,b,t; while(scanf("%lld%lld",&a,&b)&&(a+b)) { if(a<b) { t=a; a=b; b=t; } printf("%lld\n",solve(a)-solve(b-1)); } return 0; }
原文地址:http://blog.csdn.net/u012804490/article/details/24778275