Submission
Status:
Compilation Error
Subtask/Task Score:
Score: 0
User: speed_coding
Problemset: แปลงเลขฐาน
Language: cpp
Time: 0.000 second
Submitted On: 2026-10-03 11:39:57
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int n = s.length() ;
int ans = 0;
for(int i = 0; i < n; i++){
char c = s[i] ;
int container = 0;
if(c >= '0' && c <='9'){
container = c - '0';
}
else if(c>= 'A' && c<='F'){
container = c - '7';
}
ans = container *pow(16,n-1-i) + container
}
//base 2
string b ="";
int a = ans;
if (a==0){
b="0";
}
else{
while(a > 0){
if(a % 2 == 0){
b = "0" + b;
}
else{
b = "1" + b;
}
a /=2;
}
}
cout << b << "\n";
//base8
string o = "";
int b = ans;
if(b == 0){
o == "0";
}
else{
while(b > 0){
o = to_string(b%8) + o;
b /= 8;
}
}
cout << o << "\n";
return 0;
}