1049 Counting Ones

int main(){
    int n;
    cin>>n;
    int bit=1;
    int res=0;
    while(true){
        if(n/bit==0) break;
        int cur=n/bit%10;
        int high=n/bit/10;
        int low=n%bit;
        if(cur==0){
            res+=high*bit;
        }else if(cur==1){
            res+=high*bit+low+1;
        }else{
            res+=(high+1)*bit;
        }
        bit*=10;
    }
    printf("%d", res);
    return 0;
}
原文地址:https://www.cnblogs.com/FEIIEF/p/12807490.html