代码
//
// Created by Genes on 2020/12/7.
//
// 二进制中1个个数
#include <iostream>
#define ios \
ios::sync_with_stdio(false); \
cin.tie(nullptr); \
cout.tie(nullptr)
using namespace std;
const int N = 1e5 + 10;
int n, a[N];
int lowbit(int x) {
return x & (-x);
}
int main() {
ios;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
int ans = 0;
while (a[i]) {
a[i] -= lowbit(a[i]);
ans++;
}
if (i > 0) {
cout << " ";
}
cout << ans;
}
return 0;
}
还是有点问题,你左下角那三行应该是~而不是-
小白问一下,正数的反码补码不是和原码一样吗
不一样啊
(10)10 = (0000…0001010)2
反码 :1111…1110101
补码: 1111…1110110
完全一样好吗
不好意思, 傻了⊙▃⊙
niu