Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: PEPSEALSEA

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

Language: cpp

Time: 0.002 second

Submitted On: 2025-10-13 10:16:13

#include <stdio.h>
#include <iostream>
// #include <bits/stdc++.h>
using namespace std;

string digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

string cal(int nowBase , string text, int newBase){
    if (nowBase == newBase) return text;
    if (nowBase <=0 || newBase <= 0) return "0";
    int tenBaseValue = stoi(text, nullptr, nowBase);
    string newValue = "";

    if (tenBaseValue == 0) return "0";

    while (tenBaseValue > 0) {
        int moded = tenBaseValue % newBase;
        newValue += digits[moded];
        tenBaseValue /= newBase;
    }

   string reverseValue = "";
    for (int i = 0; i < int(newValue.length()); i++) {
        reverseValue += newValue[int(newValue.length()) - i - 1];
    }
    return reverseValue;
}

int main() {
    string number = "";
    
    cin >> number;

    cout << cal(16 , number , 2) << endl;
    cout << cal(16 , number , 8) << endl;

    return 0;
}