Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: limsan20122

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

Language: cpp

Time: 0.003 second

Submitted On: 2025-10-01 16:15:19

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string x;
    int y=0;
    int z=0;
    int a=0;
    int b=0;
    int c=0;
    int d=0;
    int e=0;
    int f=0;
    int g=0;
    int h=0;
    cin >> x;
    for(int i=0;i<x.length();i++){
        if(x[i]=='A') z=10;
        else if(x[i]=='B') z=11;
        else if(x[i]=='C') z=12;
        else if(x[i]=='D') z=13;
        else if(x[i]=='E') z=14;
        else if(x[i]=='F') z=15;
        else z=x[i]-'0';
        y+=(pow(16,(x.length()-i-1))*z);
    }
    a=y;
    b=y;
    e=y;
    f=y;
    while(1){
        if((a/2)>0) c++;
        else break;
        a=a/2;
    }
    while(1){
        if((b/8)>0) d++;
        else break;
        b=b/8;
    }
    c=c+1;
    d=d+1;
    for(int i=c-1;i>=0;i--){
        g=(pow(2,i));
        if((e/g)>=0) cout << (e/g);
        e=e%g;
    }
    cout << "\n";
    for(int i=d-1;i>=0;i--){
        h=(pow(8,i));
        if((f/h)>=0) cout << (f/h);
        f=f%h;
    }
    return 0;
}