Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: YourLocalZ
Problemset: แปลงเลขฐาน
Language: cpp
Time: 0.003 second
Submitted On: 2025-10-13 12:07:23
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
string hex;
long x = 0;
cin >> hex;
int s = size(hex);
for(int i=s-1;i>=0;i--)
{
if(hex[i]>=65) x += (hex[i]-'7')*pow(16,s-i-1);
else x += (hex[i]-'0')*pow(16,s-i-1);
}
//binary
long xb = x,i=15,n=0,t=0;
while(i>=0)
{
if(xb>=pow(2,i))
{
xb -= pow(2,i);
n++;
t=1;
}
else
{
if(t) cout << n;
n = 0;
i--;
}
}
cout << endl;
//octal
xb = x,i=5,n=0,t=0;
while(i>=0)
{
if(xb>=pow(8,i))
{
xb -= pow(8,i);
n++;
t=1;
}
else
{
if(t) cout << n;
n = 0;
i--;
}
}
cout << endl;
}