AcWing 3616. 进制转换
原题链接
简单
作者:
sky-koi
,
2024-11-17 21:46:12
,
所有人可见
,
阅读 2
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int stack[35];
int top;
int main() {
string s;
cin >> s;
int res = 0;
for (int i = 0; i < s.size(); i++) {
int a;
if (s[i] >= '0' && s[i] <= '9')
a = s[i] - '0';
else
a = s[i] - 'a' + 10;
if (i < s.size()) {
cout << a << " ";
} else {
cout << a;
}
res += a * pow(12, s.size() - i - 1);
}
cout << endl << res << endl;
while (res) {
stack[top++] = res % 2;
res /= 2;
}
for (int i = top; i <= 31; i++) {
stack[i] = 0;
}
int index = 0;
for (int i = 31; i >= 0; i--) {
cout << stack[i];
index++;
if (index == 8) {
cout << " ";
index = 0;
}
}
return 0;
}