Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
157878 王慕哲 二进制数问题 C++ Accepted 1 MS 264 KB 544 2026-08-18 18:03:39

Tests(1/1):


Code:

#include <iostream> using namespace std; // 判断是否为A类数 bool isClassA(int n) { int count1 = 0, count0 = 0; while (n > 0) { if (n % 2 == 1) // 当前位为1 count1++; else // 当前位为0 count0++; n /= 2; // 除以2进入下一位 } return count1 > count0; // 判断1是否多于0 } int main() { int countA = 0, countB = 0; for (int i = 1; i <= 1000; i++) { if (isClassA(i)) countA++; // 统计A类数 else countB++; // 统计B类数 } cout << countA << " " << countB << endl; // 输出结果 return 0; }