Run ID:155142

提交时间:2026-05-31 16:44:39

#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { int x; cin >> x; // 处理数字0的特殊情况 if (x == 0) { cout << 0 << endl; return 0; } string res; while (x > 0) { res += (x % 2) + '0'; x /= 2; } // 反转得到正确二进制 reverse(res.begin(), res.end()); cout << res << endl; return 0; }