Submission

Status:

PPPPPPP---

Subtask/Task Score:

70/100

Score: 70

User: YourLocalZ

Problemset: แปลงเลขฐาน

Language: cpp

Time: 0.002 second

Submitted On: 2025-10-09 11:56:12

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    string hex;
    int 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
    int 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=4,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;
    
}