提交时间:2024-08-19 22:38:55
运行 ID: 168101
#include <bits/stdc++.h> using namespace std; int cntcn(int a, int b) { int cnta = 0; int cntb = 0; for (int num = a; num <= b; ++num) { string binary = bitset<32>(num).to_string(); int ones = count(binary.begin(), binary.end(), '1'); int zeros = count(binary.begin(), binary.end(), '0'); auto pos = binary.find('1'); if (pos != string::npos) { binary = binary.substr(pos); } ones = count(binary.begin(), binary.end(), '1'); zeros = count(binary.begin(), binary.end(), '0'); if (ones > zeros) { ++cnta; } else { ++cntb; } } cout << cnta << " " << cntb << endl; return cnta + cntb; } int main() { int a, b; cin >> a >> b; cntcn(a, b); return 0; }