Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: 38408
Problemset: แปลงเลขฐาน
Language: cpp
Time: 0.005 second
Submitted On: 2026-10-15 15:36:48
#include<bits/stdc++.h>
using namespace std;
int main(){
string word;
cin >> word;
long long tran = 0;
string numtwo;
string numeg;
for (int i = 0; i < word.size(); i++)
{
int num = word[i];
if(word[i]>='A'&&word[i]<='Z'){
tran += (num -'A'+10)*pow(16,word.size()-1-i);
}else{
tran += (num -'0')*pow(16,word.size()-1-i);
}
}
long long x = tran;
while (x>0)
{
numtwo+=to_string(x%2);
x/=2;
}
while (tran>0)
{
numeg+=to_string(tran%8);
tran/=8;
}
reverse(numtwo.begin(),numtwo.end());
reverse(numeg.begin(),numeg.end());
cout << numtwo << "\n" << numeg;
}