看到二进制就要想到bitset

#include<bitset>
#include<iostream>
using namespace std;
int main(){
    int n;
    while(cin>>n){
        bitset<32> b(n);
        cout<<b.count()<<endl;
    }
}