lowbit运算会返回二进制中最后一位1
例:
x = 1010 lowbit(x) = 10
x = 101000 lowbit(x) = 1000
#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){
x-=lowbit(x);
res++;
}
cout<<res<<' ';
}
}