$\Huge\color{#4169E1}{这么多题解}$
$\Huge\color{#4169E1}{竟然没一个提到STL的?}$
C++STL库中有这么一个函数:
__builtin_popcount()
作用是统计一个 int 的二进制中有多少个 1
$$AC代码:$$
#include<bits/stdc++.h>
using namespace std;
int a[666666], n;
int main(){
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < n; i++) cout << __builtin_popcount(a[i]) << " ";
return 0;
}
x在哪里
噢噢,多谢提醒