Submission

Status:

-P--------

Subtask/Task Score:

10/100

Score: 10

User: PutterThecityboy

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

Language: cpp

Time: 0.003 second

Submitted On: 2026-10-13 22:23:40

#include <iostream>
#include <cmath>
using namespace std;
int main(){
    string n;
    cin >> n;
    long long ans = 0;
    for (int i = 0; i < n.length(); i++){
        int x;
        if (n[i] >= '0' && n[i] <= '9') {
            x = n[i] - '0';
        }
        else if (n[i] >= 'A' && n[i] <= 'F'){
            x = n[i] - 'A' + 10;
        }
        ans += x * pow(16, n.length() - 1 - i);
    }
    int a = 0;
    cout << oct << ans << endl;

    int arr[1005];
    int i = 0;
    if (ans == 0){
        cout << 0 << endl;
    } else {
        while (ans > 0){
            arr[i] = ans % 2;
            ans /= 2;
            i++;
        }
    }

    for(int j = i - 1; j >= 0; j--){
        cout << arr[j];
    }
    cout << endl;

    
    cin.ignore();
    cin.get();
    return 0;
}