提交时间:2024-08-19 20:36:29
运行 ID: 167906
#include <iostream> using namespace std; int A, B, cnt0, cnt1; int main() { int n, t, temp; cin >> n; for (int i = 1; i <= n; i++) { cnt0 = 0, cnt1 = 0; t = i; while (t) { temp = t & 1; t = t >> 1; if (temp) cnt1++; else cnt0++; } cnt1 > cnt0 ? A++ : B++; } cout << A << ' ' << B; }