Submission

Status:

----------

Subtask/Task Score:

0/100

Score: 0

User: Krispans

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

Language: cpp

Time: 0.002 second

Submitted On: 2026-09-25 11:14:18

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

int main(){

    string num;
    int ten;
    vector<int> two;
    vector<int> eight;
    cin >> num;
    for (int i=0; i<num.length(); i++){
        int digit = num[i];
        if (digit >= 49 && digit <= 58){
            digit -= 48;
        }
        else if (digit >= 65 && digit <= 70){
            digit -= 55;
        }
        ten += digit*(pow(16, num.length()-1-i));
    }
    int calc = ten;
    while (calc > 0){
        two.push_back(calc%2);
        calc /= 2;
    }
    calc = ten;
    while (calc > 0){
        eight.push_back(calc%8);
        calc /= 8;
    }
    for (int i=0; i<two.size()/2; i++){
        int temp = two[i];
        two[i] = two[two.size()-1-i];
        two[two.size()-1-i] = temp;
    }
    for (int i=0; i<eight.size()/2; i++){
        int temp = eight[i];
        eight[i] = eight[eight.size()-1-i];
        eight[eight.size()-1-i] = temp;
    }
    for(int i=0; i<two.size(); i++){
        cout << two[i];
    }
    cout << '\n';
    for(int i=0; i<eight.size(); i++){
        cout << eight[i];
    }
}