AcWing 801. 二进制中1的个数

时间:2020-07-28 14:19:17   收藏:0   阅读:88

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;
}
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!