Game of Thrones - I

  • + 1 comment

    Using parity bits in a single integer was a fun way to do this in C++. Here a 0 bit is even, a 1 bit is odd.

    int main() {
        string s;
        cin >> s;
        int parity = 0;
        for (char ch : s)
            parity ^= 1 << (ch - 'a');
        cout << (__builtin_popcount(parity) <= 1 ? "YES" : "NO") << endl;
        return 0;
    }