题解 | #查找输入整数二进制中1的个数#
查找输入整数二进制中1的个数
https://www.nowcoder.com/practice/1b46eb4cf3fa49b9965ac3c2c1caf5ad
#include <iostream> using namespace std; int sreach1(int num) { int count=0; while(num) { count++; num=num&(num-1); } return count; } int main() { int num; while (cin >>num) { cout<<sreach1(num)<<endl; } }