Skip to content

Instantly share code, notes, and snippets.

@dionyziz
Created October 21, 2019 18:25
Show Gist options
  • Save dionyziz/4454cb28910250bc26794386a418b1b8 to your computer and use it in GitHub Desktop.
Save dionyziz/4454cb28910250bc26794386a418b1b8 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main() {
const int N = 10;
int numbers[] = {0, 2, 1, 3, 10, 4, 6, 7, 8, 5};
int answer = 0;
for (int bit = 0; (1 << bit) <= N; ++bit) {
int cnt_expected = 0, cnt_actual = 0;
for (int i = 0; i <= N; ++i) {
cnt_expected += (i & (1 << bit)) != 0;
}
for (auto i: numbers) {
cnt_actual += (i & (1 << bit)) != 0;
}
if (cnt_expected > cnt_actual) {
answer |= 1 << bit;
}
}
cout << answer << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment