Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
65780 | zyqll | 二进制数问题 | C++ | Accepted | 2 MS | 268 KB | 901 | 2024-02-10 16:46:04 |
#include <iostream> #include <bitset> #include <string> #include <algorithm> using namespace std; int main() { int A = 0; int B = 0; for (int i = 1; i <= 1000; i++) { int decimalNumber = i; string binary; while (decimalNumber > 0) { binary += decimalNumber % 2 + '0'; decimalNumber /= 2; } // 反转二进制字符串 reverse(binary.begin(), binary.end()); // string binaryString = binary.to_string(); int ones = 0; int zeros = 0; for (const char c: binary) { if (c == '1') { ones++; } else { zeros++; } } if (ones > zeros) { A++; } else { B++; } } cout << A << " " << B << endl; return 0; }