Submission
Status:
PPPPPPPPPP
Score: 100
User: Namkhing
Problemset: แปลงเลขฐาน
Language: cpp
Time: 0.002 second
Submitted On: 2025-04-10 22:55:34
#include <bits/stdc++.h>
using namespace std;
int solve(string s, int k) {
int ret = 0;
for (char c : s) {
int val;
if ('A' <= c && c <= 'Z') val = 10 + c - 'A';
else val = c - '0';
ret = ret * k + val;
}
return ret;
}
string solve2(int n, int k) {
string ret = "";
while (n > 0) {
int val = n % k;
char c;
if (val >= 10) c = val - 10 + 'A';
else c = val + '0';
ret.push_back(c);
n /= k;
}
if (ret.empty()) ret.push_back('0');
reverse(ret.begin(), ret.end());
return ret;
}
int main() {
cin.tie(nullptr)->ios_base::sync_with_stdio(false);
string s;
cin >> s;
int n = solve(s, 16);
cout << solve2(n, 2) << "\n" << solve2(n, 8);
}