题解 | #求int型正整数在内存中存储时1的个数#

求int型正整数在内存中存储时1的个数

https://www.nowcoder.com/practice/440f16e490a0404786865e99c6ad91c9

use std::io::{self, *};

fn main() {
    let s = stdin().lock().lines().next().unwrap().unwrap();
    let mut n = s.parse::<i32>().unwrap();
    let mut res = 0;
    while n != 0 {
        let r = n % 2;
        if r == 1 {
            res += 1;
        }
        n /= 2;
    }
    println!("{}", res);
}

全部评论

相关推荐

给我发了笔试链接,想着等晚上回去做,结果还没做流程就终止了
伟大的小黄鸭在学习:我猜就是笔试几乎没用,就是用来给用人部门拖时间复筛简历的,可能用人部门筛到你简历觉得不合适就提前挂了
投递小鹏汽车等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务