文章

19

粉丝

0

获赞

66

访问

3.3k

头像
统计二进制数中的1的个数 题解: 移位运算
P1547 中山大学机试题
发布于2026年3月22日 20:04
阅读数 136

#include<bits/stdc++.h>
using namespace std;

int main(){
    int x;
    cin >> x;
    int count = 0;
    while(x > 0){
        if((x&1) == 1){
        count++;
    }
    x = x>>1;
    }
    cout << count  << endl;
}

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发