Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: jeeno987

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

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-10 18:17:35

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

string base(long n, int b) {
    if (n == 0) return "0";
    string s = "";
    while (n > 0) { s = char('0' + n % b) + s; n /= b; }
    return s;
}

int main() {
    string h;
    cin >> h;
    long n = 0;
    for (int i = 0; i < (int)h.size(); i++) {
        char c = h[i];
        int d = (c >= '0' && c <= '9') ? c - '0' : (c >= 'a' ? c - 'a' + 10 : c - 'A' + 10);
        n = n * 16 + d;
    }
    cout << base(n, 2) << '\n' << base(n, 8) << '\n';
    return 0;
}