C++简洁代码:
#include<bits/stdc++.h>
using namespace std;
int main () {
int n, res = 0;
cin >> n;
while(n) {
if(n % 2) res ++;
n >>= 1;
}
cout << res << endl;
return 0;
}
C++简洁代码:
#include<bits/stdc++.h>
using namespace std;
int main () {
int n, res = 0;
cin >> n;
while(n) {
if(n % 2) res ++;
n >>= 1;
}
cout << res << endl;
return 0;
}