提交时间:2024-08-19 22:18:30
运行 ID: 168082
#include <iostream> #include <vector> #include <string> using namespace std; // 函数:计算一个数的二进制表示中1和0的个数 pair<int, int> countOnesAndZeros(int num) { int ones = 0, zeros = 0; while (num > 0) { if (num % 2 == 1) ones++; else zeros++; num /= 2; } return {ones, zeros}; } // 函数:判断并统计A类和B类数的个数 pair<int, int> countABNumbers(int a, int b) { int countA = 0, countB = 0; for (int i = a; i <= b; ++i) { auto [ones, zeros] = countOnesAndZeros(i); if (ones > zeros) countA++; else countB++; } return {countA, countB}; } int main() { int a, b; cin >> a >> b; auto [countA, countB] = countABNumbers(a, b); cout << countA << " " << countB << endl; return 0; }