Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: CA

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

Language: cpp

Time: 0.002 second

Submitted On: 2026-09-25 09:23:20

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

int n;
long bin;

long tobin(int n) {
    long b = 0;
    // cout << "n = " << n << '\n';
    for (int p = 16; p >= 0; p--) {
        int pw = pow(2, p);
        long m = pow(10, p);
        if (pw <= n) {
            // cout << pw << " <= " << n << '\n';
            // cout << n << " - " << p;
            n -= pw;
            // cout << " = " << n << '\n';
            b += m;
            // cout << b << '\n';
        }
    }
    return b;
}

int main() {
    cin >> hex >> n;
    bin = tobin(n);
    cout << bin << '\n'
         << oct << n << '\n';
    return 0;
}