Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: vern6767

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

Language: cpp

Time: 0.004 second

Submitted On: 2026-09-21 15:35:25

#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main() {
    string b16;
    int b10 = 0, c16 = 0;
    cin >> b16;

    for (int i = b16.size(); i > 0; i--) {
        char n = b16[i-1];
        int num = 1;
        
        if (isalpha(n)) {
            num = n - 'A' + 10;
        } else {
            num = n - '0';
        }
        
        b10 += num*pow(16, c16);
        c16 += 1;
    } 
    
    int b101 = b10, b102 = b10;
    long long b8 = 0, b2 = 0, x = 0;
    bool cbd = true;
    
    while (cbd == true) {
        b8 += (b101%8)*pow(10, x);
        b101 = b101/8;
        x += 1;
        if (b101 == 0){
            cbd = false;
        }
    }

    cbd = true; x = 0;
    
    while (cbd == true) {
        b2 += (b102%2)*pow(10, x);
        b102 = b102/2;
        x += 1;
        if (b102 <= 0) {
            cbd = false;
        }
    }

    cout << b2 << "\n";
    cout << b8;
    return 0;
}