Submission
Status:
PPP-PPP---
Subtask/Task Score:
60/100
Score: 60
User: idkstering321
Problemset: แปลงเลขฐาน
Language: cpp
Time: 0.004 second
Submitted On: 2026-09-30 18:30:28
#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
string n, x, h;
bool identification = true;
int hello;
cin >> n;
for(int i = 0; i < n.size(); i++){
if(n[i] == 'A'){ x+="1010"; }
else if(n[i] == 'B'){ x+="1011"; }
else if(n[i] == 'C'){ x+="1100"; }
else if(n[i] == 'D'){ x+="1101"; }
else if(n[i] == 'E'){ x+="1110"; }
else if(n[i] == 'F'){ x+="1111"; }
else{
int omg = n[i]-'0';
while(omg != 0){
if(omg % 2 == 0){ h+="0"; }
else{ h+="1"; }
omg/=2;
}
reverse(h.begin(), h.end());
for(int i = 0; i < 4-h.size(); i++){ x+="0"; }
x+=h;
h.clear();
}
}
for(int i = 0; i < x.size(); i++){
if(x[i] == '0'){ continue; }
else{ hello = i; break; }
}
for(int i = hello; i < x.size(); i++){ cout << x[i]; }
cout << "\n";
hello = 0;
int y = 1;
for(int i = x.size()-1; i >= 0; i-=3){
for(int j = i; j > i-3; j--){
if(j < 0){ identification = false; break; }
hello+=((x[j]-'0')*y);
y*=2;
}
if(identification == false){ break; }
h+=to_string(hello);
hello = 0;
y = 1;
}
reverse(h.begin(), h.end());
for(int i = 0; i < h.size(); i++){
if(h[i] == '0'){ continue; }
else{ hello = i; break; }
}
for(int i = hello; i < h.size(); i++){ cout << h[i]; }
return 0;
}