码迷,mamicode.com
首页 > 其他好文 > 详细

1049 Counting Ones

时间:2020-04-30 11:16:26      阅读:53      评论:0      收藏:0      [点我收藏+]

标签:src   com   inf   break   count   bsp   +=   code   mamicode   

技术图片

 

 

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;
}

 

1049 Counting Ones

标签:src   com   inf   break   count   bsp   +=   code   mamicode   

原文地址:https://www.cnblogs.com/FEIIEF/p/12807490.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!