Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: ChanakanStudy
Problemset: แปลงเลขฐาน
Language: cpp
Time: 0.004 second
Submitted On: 2026-10-10 16:26:11
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <numeric>
#include <iomanip>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s;
cin >> s;
reverse(s.begin() , s.end());
ll number = 0;
for(int i = 0 ;i<s.size();i++) {
if(s[i] >= 'A' && s[i] <= 'Z') {
number += (s[i] - 'A' + 10) * pow(16,i);
}
else {
number += (s[i] - '0') * pow(16,i);
}
}
ll m = number;
string ans2="";
string ans8="";
while(m > 0) {
int temp = m % 2;
ans2.push_back(temp + '0');
m /= 2;
}
reverse(ans2.begin() , ans2.end());
cout << ans2 << '\n';
ll l = number;
while(l > 0) {
int temp = l % 8;
ans8.push_back(temp + '0');
l /= 8;
}
reverse(ans8.begin() , ans8.end());
cout << ans8;
return 0;
}