Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
155142 张暄浩 十进制转二进制 C++ Accepted 1 MS 276 KB 463 2026-05-31 16:44:39

Tests(20/20):


Code:

#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; }