AcWing 3616. 进制转换
原题链接
简单
作者:
sky-koi
,
2024-11-17 22:15:37
,
所有人可见
,
阅读 1
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int stack[35];
int top;
int main() {
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
int x;
if (s[i] >= 'a' && s[i] <= 'b') {
x = 10 + s[i] - 'a';
} else {
x = s[i] - '0';
}
cout << x << " ";
}
cout << endl;
int res = stoi(s, nullptr, 12); // 十进制数
cout << res << endl;
for (int i = 0; i < 32; i++)
{
stack[i] = res & 1;
res >>= 1;
}
for(int i = 31, j = 0;i >= 0; i--)
{
cout<<stack[i];
j++;
if(j == 8)
{
cout << " ";
j = 0;
}
}
cout << endl;
return 0;
}