Files
python/GESP/Level4/GESP202309/4_2.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

53 lines
977 B
C++

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 110;
int a[N], al;
string b[N];
int bl;
int main() {
LL n;
cin >> n;
if (n == 0) {
cout << "00";
exit(0);
}
while (n) {
int x = n % 2;
n /= 2;
a[++al] = x;
}
// 补全零
al = ceil(1.0 * al / 7) * 7;
for (int i = al; i > 1; i -= 7) {
string s = "";
for (int j = i; j > i - 7; j--)
s = s + to_string(a[j]);
if (i == 7)
b[++bl] = "1" + s;
else
b[++bl] = "0" + s;
}
// 2进制4位一组生成16进制数
for (int i = bl; i >= 1; i--) {
// cout << b[i] << endl;
for (int j = 0; j < b[i].size(); j += 4) {
int x = (b[i][j] - '0') * 8 + (b[i][j + 1] - '0') * 4 +
(b[i][j + 2] - '0') * 2 + (b[i][j + 3] - '0');
if (x >= 10)
cout << char(x - 10 + 'A');
else
cout << x;
}
cout << " ";
}
return 0;
}