1. #include <iostream>
    2. using namespace std;
    3. //查找二进制数最后一个1
    4. int lowbit(int x)
    5. {
    6. return x & -x;
    7. }
    8. int main()
    9. {
    10. ios::sync_with_stdio(false);
    11. cin.tie(0);
    12. cout.tie(0);
    13. int n;
    14. cin >> n;
    15. while(n --)
    16. {
    17. int x;
    18. cin >> x;
    19. int res = 0;
    20. while(x) x -= lowbit(x), res ++;// 每次减去x最后一位1
    21. cout << res << " ";
    22. }
    23. }