提交时间:2024-08-19 22:45:05

运行 ID: 168113

#include <iostream> #include <vector> using namespace std; int decimalToBinary(int decimal) { vector<int> binary; int cntOne = 0; int cntZero = 0; while (decimal > 0) { binary.push_back(decimal % 2); decimal /= 2; } for (int i = binary.size() - 1; i >= 0; --i) { if (binary[i] == 1) { ++cntOne; } else { ++cntZero; } } if (cntOne>cntZero) return 1; else return 0; } int main() { int start,end, cntOnes=0, cntZeros=0; cin >> start>>end; for (int i=start;i<=end;i++){ if (decimalToBinary(i) == 1){ cntOnes++; } else{ cntZeros++; } } cout << cntOnes<< " "<<cntZeros; return 0; }