Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: yume_snowy
Problemset: แปลงเลขฐาน
Language: cpp
Time: 0.002 second
Submitted On: 2026-10-11 19:07:40
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
string base_16;
cin >> base_16;
int base_10 = 0;
reverse(base_16.begin(),base_16.end());
for (int i=0; i<base_16.size(); i++) {
if (base_16[i] >= '0' && base_16[i] <= '9') base_10 += ((base_16[i]-'0')*pow(16,i));
else {
base_10 += (10+(base_16[i]-'A')) * pow(16,i);
}
}
int num = base_10;
vector<int>base_2;
vector<int>base_8;
while (num > 0) {
base_2.push_back(num%2);
num/=2;
}
reverse(base_2.begin(),base_2.end());
num = base_10;
while (num > 0) {
base_8.push_back(num%8);
num/=8;
}
reverse(base_8.begin(),base_8.end());
for (int i=0; i<base_2.size(); i++) cout << base_2[i];
cout << "\n";
for (int i=0; i<base_8.size(); i++) cout << base_8[i];
}