Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: uraniumconsumer

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

Language: cpp

Time: 0.004 second

Submitted On: 2026-09-27 13:24:41

#include <bits/stdc++.h>
using namespace std;

int main(){
    string hex;
    cin >> hex;
    int a = 0;

    for(int i = 0; i < hex.length(); i++){
        int hex2 = hex[i] - '0';
        if(hex[i] == 'A'){
            hex2 = 10;
        }
        else if(hex[i] == 'B'){
            hex2 = 11;
        }
        else if(hex[i] == 'C'){
            hex2 = 12;
        }
        else if(hex[i] == 'D'){
            hex2 = 13;
        }
        else if(hex[i] == 'E'){
            hex2 = 14;
        }
        else if(hex[i] == 'F'){
            hex2 = 15;
        }
        a += hex2 * (pow(16, (hex.length() - i - 1)));
    }

    int tempa = a;

    int c = 0;
    string d = "";

    while(tempa>0){
        c = tempa % 2;
        tempa = tempa/2;
        string b = to_string(c);
        d = d + b;
    }
    int e = d.length();
    while(e>0){
        cout << d[e-1];
        e = e-1;
    }
    cout << '\n';
    //decimal -> octal
    //31 = 37
    // 31/8 = 3 r. 7
    // 3/8 = 0 r. 3
    // 73 -> 37
    int tempa2 = a;

    int b = 0;
    string f = "";

    while(tempa2>0){
        b = tempa2 % 8;
        tempa2 = tempa2/8;
        string v = to_string(b);
        f = f + v;
    }
    int g = f.length();
    while(g>0){
        cout << f[g-1];
        g = g - 1;
    }
}