题解 | 牛牛的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")

全部评论

相关推荐

03-29 18:59
运城学院 Java
程序员小白条:咱们要对自己的简历和学历有清晰的认知,不要动不动就大厂了....都26届了,没实习还想着大厂,唉
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务