给定一个长度为 n 的数列,请你求出数列中每个数的二进制表示中 1 的个数。
#include <iostream> using namespace std; int lowbit (int x) { return x & (-x); } int main() { int n; scanf ("%d", &n); while (n--) { int x; scanf ("%d", &x); int cnt = 0; while (x) { x -= lowbit(x); cnt++; } printf ("%d ", cnt); } return 0; }
标签:cnt,return,二进制,scanf,个数,int From: https://www.cnblogs.com/leetothemoon/p/16939806.html