题解 | #查找输入整数二进制中1的个数#
查找输入整数二进制中1的个数
https://www.nowcoder.com/practice/1b46eb4cf3fa49b9965ac3c2c1caf5ad
/*
* @Description: If you get question about the code, contact me at **********.
* @Author: pengjunxing
* @Date: 2023-02-10 19:59:42
* @LastEditors: pengjunxing
* @LastEditTime: 2023-02-10 20:02:36
*/
#include<iostream>
using namespace std;
int count(int n)
{
int time=0;
while(n)
{
if(n%2)
{
time++;
}
n/=2;
}
return time;
}
int main()
{
int num;
while(cin>>num)
{
cout<<count(num)<<endl;
}
}
查看9道真题和解析