123456789

nztao  •  11个月前


#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int convertToDecimal(int n, string x) {
    int decimal = 0;
    int power = 0;

    for (int i = x.length() - 1; i >= 0; i--) {
        int digit = x[i] - '0';
        decimal += digit * pow(n, power);
        power++;
    }

    return decimal;
}

int main() {
    int n;
    string x;
    cin >> n >> x;

    int decimal = convertToDecimal(n, x);
    cout << decimal << endl;

    return 0;
}

评论:

请先登录,才能进行评论