Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: helloskibidi
Problemset: แปลงเลขฐาน
Language: cpp
Time: 0.002 second
Submitted On: 2026-10-04 22:59:53
#include <bits/stdc++.h>
using namespace std;
int main(){
string n;
cin >> n;
string hexchar = "ABCDEF";
int base10 = 0;
for(int i=0;i<n.length();i++){
int temp = n[i] - '0';
for(int j=0;j<hexchar.length();j++){
if(n[i] == hexchar[j]) temp = 10 + j;
}
base10 += temp* pow(16,n.length() - i - 1);
}
string binary = "";
int base102 = base10;
while(base10>0){
string rem = to_string(base10%2);
binary = rem + binary;
base10 /=2;
}
string octonary = "";
while(base102>0){
string rem = to_string(base102%8);
octonary = rem + octonary;
base102 /= 8;
}
cout << binary << "\n" << octonary;
}