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

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

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

#include <bits/stdc++.h>
#include <bitset>
using namespace std;

int main() {
    int n;
    cin >> n;
    bitset<32> binary(n);
    string s = binary.to_string();
    int counts = 0;
    for(auto &num : s)
        if(num=='1')
            counts++;
    cout<<counts<<endl;
    return 0;
}

全部评论

相关推荐

大世界中的渺小一棵:看出来你软硬都有基础,但是这样写简历软硬都擦边不知道你想投什么,建议针对岗位jd针对性修改下。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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