Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: Nuchkul
Problemset: แปลงเลขฐาน
Language: cpp
Time: 0.004 second
Submitted On: 2026-10-02 14:57:48
#include<iostream>
#include<string>
using namespace std;
void pbase(int n,int base){
if(n==0){
cout << "0";
return;
}
int arr[20];
int count = 0;
while(n>0){
arr[count] = n%base;
n = n/base;
count++;
}
for(int i=count-1;i>=0;i--){
cout << arr[i];
}
cout << endl;
}
int main(){
string hex;
cin >> hex;
int d=0;
for(int i=0;i<hex.length();i++){
int value;
if(hex[i] >= '0' && hex[i] <= '9'){
value = hex[i] - '0';
}
else if(hex[i] >= 'A' && hex[i] <= 'F'){
value = hex[i] - 'A' + 10;
}
else{
value = hex[i] - 'a' + 10;
}
d = d*16+value;
}
pbase(d,2);
pbase(d,8);
}