Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
168035 | Mino_XIE-谢文凯B班 | 二进制分类 | C++ | 通过 | 100 | 0 MS | 248 KB | 870 | 2024-08-19 21:58:00 |
#include <iostream> #include <string> using namespace std; string toBinary(int n) { string binary = ""; while (n > 0) { binary = (n % 2 == 0 ? "0" : "1") + binary; n /= 2; } return binary.empty() ? "0" : binary; } int main() { int a, b; cin >> a >> b; if (a > b) { swap(a, b); } int countA = 0, countB = 0; for (int i = a; i <= b; ++i) { string binary = toBinary(i); int count1 = 0, count0 = 0; for (char bit : binary) { if (bit == '1') { count1++; } else { count0++; } } if (count1 > count0) { countA++; } else { countB++; } } cout << countA << " " << countB << endl; return 0; }