Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: Kei
Problemset: แปลงเลขฐาน
Language: cpp
Time: 0.003 second
Submitted On: 2026-10-07 15:14:56
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve(){
//b16->b2&b8
map<char, string> table = {
{'0', "0000"},
{'1', "0001"},
{'2', "0010"},
{'3', "0011"},
{'4', "0100"},
{'5', "0101"},
{'6', "0110"},
{'7', "0111"},
{'8', "1000"},
{'9', "1001"},
{'A', "1010"},
{'B', "1011"},
{'C', "1100"},
{'D', "1101"},
{'E', "1110"},
{'F', "1111"}
};
map<string, char> table8 = {
{"000", '0'},
{"001", '1'},
{"010", '2'},
{"011", '3'},
{"100", '4'},
{"101", '5'},
{"110", '6'},
{"111", '7'}
};
string s,the2="",the8="",thestr; cin >> s;
for(char& c : s){
the2+=table[c];
}
int p=0;
while(p+1<(int)the2.size() && the2[p]=='0')p++;
the2=the2.substr(p);
cout<<the2<<'\n';
if(the2.size()%3==1) the2="00"+the2;
if(the2.size()%3==2) the2='0'+the2;
for(int i=0;i<the2.size()/3;i++){
thestr=the2.substr(3*i,3);
the8+=table8[thestr];
}
cout<<the8;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}