题解 | #求int型正整数在内存中存储时1的个数#
求int型正整数在内存中存储时1的个数
https://www.nowcoder.com/practice/440f16e490a0404786865e99c6ad91c9
#include <iostream> using namespace std; int main() { int a, b; cin >> a;// 注意 while 处理多个 case if(a == 0) { cout<<0<<endl; return 0;; } while (a>=1) { b += a%2; a /=2; } cout << b<<endl; } // 64 位输出请用 printf("%lld")
数到位数转换:取余数,取到余数为0;保留之前到所有余数