题解 | #查找输入整数二进制中1的个数#

查找输入整数二进制中1的个数

https://www.nowcoder.com/practice/1b46eb4cf3fa49b9965ac3c2c1caf5ad

没啥难度,十进制转换为二进制,再统计二进制中1的数目
#include <iostream>
#include <set>
using namespace std;

int main(){
    int n = 0;
    while (cin >> n) {
        multiset<int> res;
        int rem = n % 2;
        n /= 2;
        res.insert(rem);
        while (n != 0) {
            rem = n % 2;
            n /= 2;
            res.insert(rem);
        }
        int count = res.count(1);
        cout << count << endl;
    }
    return 0;
}


全部评论

相关推荐

Sigma429:极兔啊,薪资开的巨低,还在上海,索性不做笔试了
点赞 评论 收藏
分享
我的代码出BUG了:@美团@腾讯@字节跳动@阿里巴巴。你们好好看看吧,你们就挂我吧,到时候被人家鸽穿还得录取我
点赞 评论 收藏
分享
09-28 18:14
门头沟学院 Java
小肥罗:离谱,那我的简历可以这么写:颜值高大长腿,一张臭嘴不要脸,四只眼瓜子脸,入职不用买保险。
我的秋招日记
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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