统计每一位上1的个数
class Solution {
public:
int countDigitOne(int n) {
if(n<=0) return 0;
int ans=0,k=1;
string s="0"+to_string(n);
for(int i=2;i<s.size();++i) k*=10;
for(int i=1;i<s.size();++i){
if(s[i]=='0') ans+=stod(string(s,0,i))*k;
else if(s[i]=='1') ans+=stod(string(s,0,i))*k+(i==s.size()-1? 0:stod(string(s,i+1,99)))+1;
else ans+=(1+stod(string(s,0,i)))*k;
k/=10;
}
return ans;
}
};