Run ID:108063
提交时间:2025-01-19 14:19:48
#include <iostream> using namespace std; int main() { int a; cin >> a; if (a == 0) { cout << 0; return 0; } // Use a stack-like approach with division and modulus int b = 0; int c = 1; while (a > 0) { int d = a % 2; b = b + d * c; c *= 10; a = a / 2; } // Reverse the digits of b to get the correct binary representation int e = 0; while (b > 0) { e = e * 10 + b % 10; b /= 10; } cout << e << endl; return 0; }