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

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

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

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

int main() {
    int n;
    cin >> n;
    vector<int> s;
    while(n) {
        int num =  n % 2;
        s.push_back(num);
        n /= 2;
    }
    int count = 0;
    for(auto a : s) {
        if(a == 1) {
            count++;
        }
        
    }
    cout << count << endl;
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

不多说了,看图吧
MomonKa:实际上是,机房机器有些高度,问问你身高,有没有女朋友是看你能不能猛猛加班
你最讨厌面试问你什么?
点赞 评论 收藏
分享
07-07 12:25
门头沟学院 Java
程序员牛肉:你这个智邮公司做的就是那个乐山市税务系统的服务吗?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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