Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: angpangSK

Problemset: แปลงเลขฐาน

Language: cpp

Time: 0.003 second

Submitted On: 2025-09-23 21:30:07

#include <iostream>
using namespace std;

int hexToDec(string hex) {
  int dec = 0;
  for (int i = 0; i < hex.length(); i++)
    dec = dec * 16 + (hex[i] >= 'A' ? hex[i] - 'A' + 10 : hex[i] - '0');
  return dec;
}
string DectoBin(int dec) {
  string bin = "";
  while (dec != 0) {
    bin = to_string(dec % 2) + bin;
    dec = dec / 2;
  }
  return bin;
}
string DectoOct(int dec) {
  string oct = "";
  while (dec != 0) {
    oct = to_string(dec % 8) + oct;
    dec = dec / 8;
  }
  return oct;
}

int main() {
  string hex;
  cin >> hex;
  int dec = hexToDec(hex);
  string binary = DectoBin(dec);
  string octal = DectoOct(dec);
  cout << binary << endl;
  cout << octal;
  return 0;
}