思路
- x=x-lowbit(x)
- lowbit(x)=x&-x=x&(~x+1)
- x=x&(x-1)
c++
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int n;
scanf("%d",&n);
while(n--){
int x;
scanf("%d",&x);
int res=0;
while(x){
x=x&(x-1);
res++;
}
printf("%d ",res);
}
return 0;
}