1 条题解
-
0
练43.2十进制转十六进制
解题思路
用十六进制流格式hex输出,并用uppercase让A~F大写。
正确性说明
计算规则直接来自题目定义。按所述顺序处理时,已完成部分的结果被准确保存在累加量、计数或当前状态中;下一步只加入新增贡献。最终得到完整要求的结果。
易错点
不输出0x前缀。
复杂度
输出位数D,时间O(D),额外空间O(1)。
参考代码(C++11)
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long n; cin >> n; cout << hex << uppercase << n << "\n"; return 0; }
- 1