题解 | 二进制数1

二进制数1

https://www.nowcoder.com/practice/bc4c7936f5ed42cbb9131b6f39aa272b

#include <iostream>
using namespace std;

int main()
{
    long long x;cin>>x;
    int count=0;
    while(x)
    {
        count++;
        x&=(x-1);//每次移除最低位的1
    }
    cout<<count<<endl;
    return 0;
}

全部评论

相关推荐

gelmanspar...:奖学金删掉,自我评价删掉,简历压缩一下,写一页
如果再来一次,你还会学机...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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