Submission
Status:
----------
Subtask/Task Score:
0/100
Score: 0
User: helloskibidi
Problemset: แปลงเลขฐาน
Language: cpp
Time: 0.004 second
Submitted On: 2026-10-04 22:58:41
#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);
cout << temp *pow(16,n.length() - i - 1) << endl;
}
// cout << base10;
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;
}