Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: polikanta

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

Language: cpp

Time: 0.002 second

Submitted On: 2026-10-08 21:01:07

#include<iostream>
using namespace std;
int main(){
    string h;
    cin >> h;
    int num = 0;
    for(int i = 0; i < h.length(); i++){
        char c = h[i];
        int val = 0;
        if (c >= '0' && c <= '9'){
            val = c - '0';
        }
        else if(c >= 'A' && c <= 'F'){
            val = c - 'A' + 10;
        }
        num = (num * 16)+ val;
    }
    if (num == 0){
        cout << "0\n";
        cout << "0\n";
    }
    else {
        string b = "";
        int temp2 = num;
        while (temp2 > 0){
            if (temp2 % 2 == 0){
                b = "0" + b;
            }
            else {
                b = "1" + b;
            }
            temp2 = temp2 / 2;
        }
        cout << b << "\n";
        string o ="";
        int temp8 = num;
        while(temp8 > 0){
            int r = temp8 % 8;
            char d = r + '0';
            o = d + o;
            temp8 = temp8 / 8;
        }
        cout << o << "\n";
    }
    return 0;
}