<span>AcWing 801. 二进制中1的个数</span>

AcWing 801. 二进制中1的个数


#include <bits/stdc++.h>
using namespace std;
int lowbit(int x){
    return x&-x;
}
int main(){
    int n;
    cin>>n;
    while(n--){
        int x,res=0;
        cin>>x;
        while(x) /*printf("当前x的值:%d ",x),*/x-=lowbit(x),res++;
        //printf("%d\n",x);
        //cout<<"1的个数:"<<res<<" ";
        cout<<res<<" ";
        //printf("\n---\n");
    }
    return 0;
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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