#50532: 2~9轉10進位皆可(改 base 參數即可)


11155088@gs.hs.ntnu.edu.tw (ace1110)

學校 : 不指定學校
編號 : 298370
來源 : [118.169.28.170]
最後登入時間 :
2025-09-24 21:58:03

#include <iostream>
#include <string>
#include <algorithm>
#include <stdexcept>

typedef long long BigInt;

// 將字串轉成 10 進位 BigInt
BigInt baseToDecimal(const std::string& num, BigInt base) {
    BigInt result = 0;
    for (char c : num) {
        BigInt digit = c - '0';
        result = result * base + digit;
    }
    return result;
}

int main() {
    std::string num;
    BigInt base = 9;
    std::cin >> num;
    std::cout << baseToDecimal(num, base);
    return 0;
}