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

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

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

/*
 * @Description: If you get question about the code, contact me at **********.
 * @Author: pengjunxing
 * @Date: 2023-02-10 19:59:42
 * @LastEditors: pengjunxing
 * @LastEditTime: 2023-02-10 20:02:36
 */
#include<iostream>
using namespace std;
int count(int n)
{
    int time=0;
    while(n)
    {
        if(n%2)
        {
            time++;
        }
        n/=2;
    }
    return time;
}
int main()
{
    int num;
    while(cin>>num)
    {
        cout<<count(num)<<endl;
    }
}

全部评论

相关推荐

07-02 10:44
门头沟学院 C++
码农索隆:太实诚了,告诉hr,你能实习至少6个月
点赞 评论 收藏
分享
06-07 17:17
嘉兴学院 教师
心爱的idea:你孩
点赞 评论 收藏
分享
06-16 15:04
黑龙江大学 Java
零OFFER战士:另一个版本查看图片
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-04 18:02
好不容易拿到了字节Offer,鼠鼠做后端的,但家里人觉得可能被裁员不稳定,让鼠鼠去投国企,现在好纠结到底该咋选
文档传偷助手:该投就投吧,不过建议别放弃offer 拿到手里的才是最好的
投递字节跳动等公司9个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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