位运算
求二进制中的1。
突然发现得转c++
#include<iostream>
using namespace std;
int Countone(long long x){
int res=0;
while(x){
res += x & 1;
x = x >> 1;
}
return res;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
long long n,x;
cin >> n;
for (int i = 0; i < n; i ++ ){
cin >> x;
cout << Countone(x) << " ";
}
return 0;
}