Submission

Status:

----------

Subtask/Task Score:

0/100

Score: 0

User: colo39

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

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-01 13:26:44

#include <bits/stdc++.h>
using namespace std;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int sz = s.size();
    int base_10 = 0;
    int j = 0;
    for (int i = sz - 1;i >= 0;i--) {
        if (isdigit(s[j])) {
            base_10 += pow(16,i) * (s[j] - '0');
        } else {
            if (s[j] == 'A') base_10 += pow(16,i) * (10);
            if (s[j] == 'B') base_10 += pow(16,i) * (11);
            if (s[j] == 'C') base_10 += pow(16,i) * (12);
            if (s[j] == 'D') base_10 += pow(16,i) * (13);
            if (s[j] == 'E') base_10 += pow(16,i) * (14);
            if (s[j] == 'F') base_10 += pow(16,i) * (15);
        }
        j++;
    }
    //cout << base_10;
    string ans = "";
    while (base_10 != 0) {
        ans = to_string(base_10 % 8) + ans;
        base_10 /= 8;
    }
    cout << ans;
}