难道没有人想起他吗?
查看原帖
难道没有人想起他吗?
1777044
xiaolong6666楼主2025/6/30 18:23

此题是关于十进制转二进制的题目 但是我好像是这么写的。。。


#include <iostream>
using namespace std;

int main() {
    int n, totalOnes = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        // 用 __builtin_popcount 统计二进制中 1 的个数(仅适用于 int 范围)
        totalOnes += __builtin_popcount(x);
    }
    // 输出总个数 和 奇偶性
    cout << totalOnes << " " << (totalOnes % 2) << endl;
    return 0;
}

真的没有人记得__builtin_popcount吗?

2025/6/30 18:23
加载中...