#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cmath>
using namespace std;
int main()
{
string s;
cin >> s;
vector<char>m;
for (int i = 0; i < s.length(); i++)
{
if (s[i] == '#')
{
break;
}
m.push_back(s[i]);
}
int sum = 0;
// cout << m.size();
for (int i = 0; i < m.size(); i++)
{
sum = sum * 2 + int(s[i] - '0');
}
cout << sum << endl;
vector<int>eight;
int sum3 = sum;
while (sum3 != 0)
{
eight.push_back(sum3 % 8);
sum3 = sum3 / 8;
}
for (int i = 0; i < eight.size(); i++)
{
cout << eight[eight.size() - i - 1];
}
cout << endl;
vector<int>sixteen1;
int sum4 = sum;
while (sum4 != 0)
{
sixteen1.push_back(sum4 % 16);
sum4 = sum4 / 16;
}
for (int i = 0; i < sixteen1.size(); i++)
{
// cout << sixteen1[sixteen1.size() - i - 1];
}
vector<char>sixteen;
for (int i = 0; i < sixteen1.size(); i++)
{
if (sixteen1[i] >= 0 && sixteen1[i] <= 9)
{
char pp = char(sixteen1[i]) + '0';
sixteen.push_back(pp);
}
else if (sixteen1[i] >= 10 && sixteen1[i] <= 15)
{
char pp = char(sixteen1[i] - 10) + 'a';
sixteen.push_back(pp);
}
// cout << sixteen[sixteen.size() - i - 1];
}
for (int i = 0; i < sixteen.size(); i++)
{
cout << sixteen[sixteen.size() - i - 1];
}
cout << endl;
return 0;
}
进制转换c++
最新推荐文章于 2024-08-31 22:41:09 发布