码迷,mamicode.com
首页 > Windows程序 > 详细

AcWing 801. 二进制中1的个数

时间:2020-07-28 14:19:17      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:--   pac   space   ++   ret   using   std   pre   while   

AcWing 801. 二进制中1的个数


#include <bits/stdc++.h>
using namespace std;
int lowbit(int x){
    return x&-x;
}
int main(){
    int n;
    cin>>n;
    while(n--){
        int x,res=0;
        cin>>x;
        while(x) /*printf("当前x的值:%d ",x),*/x-=lowbit(x),res++;
        //printf("%d\n",x);
        //cout<<"1的个数:"<<res<<" ";
        cout<<res<<" ";
        //printf("\n---\n");
    }
    return 0;
}

AcWing 801. 二进制中1的个数

标签:--   pac   space   ++   ret   using   std   pre   while   

原文地址:https://www.cnblogs.com/wiseXu/p/13390447.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!