题解 | #查找输入整数二进制中1的个数#
查找输入整数二进制中1的个数
http://www.nowcoder.com/practice/1b46eb4cf3fa49b9965ac3c2c1caf5ad
#include<bits/stdc++.h>
using namespace std;
void process(int num, int& res){
while(num != 0){
res++;
num = num & (num - 1);
}
}
int main(){
int num = 0;
while(cin>>num){
int res = 0;
process(num, res);
cout<<res<<endl;
}
return 0;
}
华为题库题解 文章被收录于专栏
牛客华为题库的题解
查看1道真题和解析
