题解 | 牛牛的10类人
牛牛的10类人
https://www.nowcoder.com/practice/232b7fc32fac4636819e31a7d7c960a3
#include <iostream>
using namespace std;
string Binary(int a) {
string s;
char c;
while (a != 0) {
c = a % 2+'0';
a = a / 2;
s.push_back(c);
}
return s;
}
int main() {
int n, a, n0 = 0, n1 = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
string s = Binary(a);
for (int j = 0; j < s.length(); j++) {
if (s[j] == '0') {
n0++;
} else if (s[j] == '1') {
n1++;
}
}
if (n0 % 2 == 0 && n1 % 2 == 0) {
cout << "10" << " ";
} else if (n0 % 2 == 0) {
cout << "0" << " ";
} else if (n1 % 2 == 0) {
cout << "1" << " ";
} else {
cout << "100" << " ";
}
n0=0;
n1=0;
}
return 0;
}
// 64 位输出请用 printf("%lld")
查看7道真题和解析