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

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

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

#include <iostream>
int main()
{
    using namespace std;
    int number = 0;
    
    while(cin>>number)
    {
        int i = 0;
        if(number == 0)
        {
            cout<<i<<endl;
        }
        else
        {
            while(number)
            {
                number &= number-1;
                i++;
            }
            cout<<i<<endl;
        }
    }
    return 0;
}
全部评论

相关推荐

找到实习了&nbsp;给了150一天&nbsp;但是说是低代码&nbsp;值得去吗
码农索隆:是在没实习,可去,待个一两周,不行就润呗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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