Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: pupu

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

Language: cpp

Time: 0.003 second

Submitted On: 2026-11-30 09:50:07

#include <iostream>
#include <cmath>
using namespace std;
int main(){ios::sync_with_stdio(0); cin.tie(0);
    string sixteen;
    long long int hold,sum=0,c=0,sec=0,eigth=0;
    cin>>sixteen;
    c=sixteen.length() - 1;
    for(int i=0;i<sixteen.length();i++){
        if(int(sixteen[i])<=57 and int(sixteen[i])>=48){
            sum+=(int(sixteen[i]) - 48)* pow(16,c);
        }
        if(int(sixteen[i])<=90 and int(sixteen[i])>=65){
            sum+=(int(sixteen[i]) - 64 + 9)* pow(16,c) ;
        }
        c--;
    }
    hold=sum;
    c=0;
    while(hold>0){
        if(hold % 2 == 1){
            sec += pow(10,c);
        }
        if(hold == 1){
            break;
        }
        hold/=2;
        c++;
    }
    hold=sum;
    c=0;
    while(hold>0){
        eigth += pow(10,c) * (hold%8);
        if(hold < 8){
            break;
        }
        hold/=8;
        c++;
    }
    cout<<sec<<"\n"<<eigth;
}