#include <stdio.h>

int func(int x) { 
    int countx = 0; 
    while(x) { 
        countx ++; 
        x = x & (x - 1); 
    } 
    return countx; 
} 

int main() {
    int x;
    int cnt=0;
    while( scanf("%d",&x)!=EOF)
    {
     cnt= func(x);
    printf("%d\n",cnt);
    }

}

可看之前写的一篇题解

https://www.nowcoder.com/practice/440f16e490a0404786865e99c6ad91c9