Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: Sunsblad

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

Language: cpp

Time: 0.004 second

Submitted On: 2026-09-30 19:24:11

#include<iostream>
#include<string>
#include<stack>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string hex;
    int deci = 0;
    stack<int> binary;
    stack<int> eighth;
    cin>>hex;
    for(int i = 0; i < hex.size(); i++){
        if(hex[i] >= 'A'){
            deci += int(hex[i]) - int('A') + 10;
        }else{
            deci += int(hex[i]) - int('0');
        }
        if(i  < hex.size() - 1){
            deci *= 16;
        }
    }
    int tmp = deci;
    while(tmp > 0){
        eighth.push(tmp % 8);
        binary.push(deci % 2);
        tmp /= 8;
        deci /= 2;
    }
    while(deci > 0){
        binary.push(deci % 2);
        deci /= 2;
    }
    while(!binary.empty()){
        cout<<binary.top();
        binary.pop();
    }
    cout<<'\n';
    while(!eighth.empty()){
        cout<<eighth.top();
        eighth.pop();
    }
    
    

    
}