在阿里巴巴吃到的蜇
#include <stdio.h>
int printer(int x)
{
int counter = 0;
while(x) {
counter++;
x = x & (x-1);//算一的个数
}
return counter;
}
int main()
{
printf("%d\n", printer(9999));
return 0;
}
{
int counter = 0;
while(x) {
counter++;
x = x & (x-1);//算一的个数
}
return counter;
}
int main()
{
printf("%d\n", printer(9999));
return 0;
}