题解 | #求int型正整数在内存中存储时1的个数#
求int型正整数在内存中存储时1的个数
https://www.nowcoder.com/practice/440f16e490a0404786865e99c6ad91c9
#include <iostream>
using namespace std;
int main() {
int a;
while (cin >> a) {
int n = 0;
//处理余数为1部分
while (a / 2 !=0) {
if (a % 2 == 1)
n++;
a = a / 2;
}
//处理右移2结束后为1的部分
if (a == 1) {
n++;
}
cout << n << endl;
}
}
// 64 位输出请用 printf("%lld")
