Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: HawThorns
Problemset: แปลงเลขฐาน
Language: cpp
Time: 0.004 second
Submitted On: 2026-10-07 21:53:30
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
string findsbase2(int total,int divideby){
string temp ="";
int left = total;
string toadd;
while(left >= divideby){
int thing = left %divideby;
left = left/divideby;
//cout << thing << endl;
if(thing >= 10){
toadd = 'A' + thing -10;
}
else
{
toadd = to_string(thing);
}
//cout << left<< " " << toadd<<endl;
temp.insert(0 ,toadd);
}
if(left >= 10){
toadd = 'A' + left -10;
}
else
{
toadd = to_string(left);
}
temp.insert(0 ,toadd);
return temp;
}
int main(){
long long total = 0;
string input;
cin >> input;
int i = 0;
for(i = 0;i < input.size() ;i++){
if(input[i] >= 'A'){
total += (input[i] -'A' + 10 ) * pow(16, input.size() - i-1);
}
else
{
total += (input[i] -'0') * pow(16, input.size() -1- i);
}
}
//cout << total << endl;
cout << findsbase2(total,2)<<endl;
cout << findsbase2(total,8);
return 0;
}