<<剑指offer>>的解释没有编程之美的解释好。建议这题看编程之美的解释
long long CountOne(long long n) { long long iCount = 0; long long ifactor = 1; long long ilower, icur, ihigher; while( n/ifactor != 0) { ilower = n % ifactor ; icur = (n/ifactor )%10 ; ihigher = n/(ifactor*10); switch(icur){ case 0: iCount += ihigher * ifactor;break; case 1: iCount += ihigher * ifactor + ilower + 1; break; default : iCount += (ihigher +1) * ifactor; } ifactor *= 10; } return iCount; }