Submission
Status:
PxPP------
Subtask/Task Score:
30/100
Score: 30
User: santanaja07
Problemset: แปลงเลขฐาน
Language: cpp
Time: 0.003 second
Submitted On: 2025-09-21 20:28:49
#include <iostream>
#include <string>
using namespace std;
int main()
{
string c;
cin>>c;
int eight,two,ten;
int t=1;
ten=0;
for(int i=0;i<=c.length()-2;i++){
if(c[i]=='A'||c[i]=='B'||c[i]=='C'||c[i]=='D'||c[i]=='E'||c[i]=='F'){
t=t*(int(c[i])-55)*16;
}else{
t=t*(int(c[i])-48)*16;
}
}
ten+=t;
if(c[c.length()-1]=='A'||c[c.length()-1]=='B'||c[c.length()-1]=='C'||c[c.length()-1]=='D'||c[c.length()-1]=='E'||c[c.length()-1]=='F'){
ten+=(int(c[c.length()-1])-55);
}else{
ten+=(int(c[c.length()-1])-48);
}
int copyten;
copyten=ten;
string strtwo="",streight="";
while(ten>0){
strtwo= char(ten%2+'0') + strtwo;
ten=ten/2;
}
while(copyten>0){
streight= char(copyten%8+'0') + streight;
copyten=copyten/8;
}
cout<<strtwo<<endl;
cout<<streight;
return 0;
}