题目描述
模板题:lowbit
C++代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, num;
int a[N];
int lowbit(int x){
return x & -x;
}
int main(){
cin >> n;
for(int i = 0; i < n; i++){
cin >> a[i];
int x = a[i];
num = 0;
while(x){
x -= lowbit(x);
num++;
}
cout << num << " ";
}
cout << endl;
}