Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: Folk_DIWA
Problemset: แปลงเลขฐาน
Language: cpp
Time: 0.004 second
Submitted On: 2026-10-12 22:52:32
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll to_10(string n, int base){
ll res = 0;
for(char &c : n){
ll digit = isdigit(c) ? c - '0' : toupper(c) - 'A' + 10;
res = res*base + digit;
}
return res;
}
string convert(ll n, int base){
string digit = "0123456789ABCDEF";
string res = "";
if(n == 0) return "0";
while(n > 0){
res += digit[n%base];
n /= base;
}
reverse(res.begin(), res.end());
return res;
}
int main(){
cin.tie(0)->sync_with_stdio(0);
string s; cin >> s;
ll n = to_10(s, 16);
cout << convert(n, 2) << '\n' << convert(n, 8);
return 0;
}