代码实现
#include分析int main(){ int n;scanf("%d",&n); while(n--){ int count = 0; int x;scanf("%d",&x); while(x){ x ^= x & -x;//x -= x & -x; count ++; } printf("%d ",count); } return 0; }
lowbit(x)是x的二进制表达式中最低位的1所对应的值。
int lastone =-x & -x 算出最后一位1
然后再循环即可,x -= lastone 保险使用 x ^= lastone



