Submission

Status:

Compilation Error

Subtask/Task Score:

Score: 0

User: Newton4566

Problemset: บวกเลขฐาน

Language: cpp

Time: 0.000 second

Submitted On: 2026-10-10 15:21:37

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

string toBase(LL n, int b) {
    if (n == 0) return 0;
    string digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string s = "";

    while (n > 0) {
        s += digits[n % b];
        n /= b;
    }
    reverse(s.begin(), s.end());

    return s;
}

LL fromBase(const string& s, int b) {
    LL result = 0;
    int i = 0;

    for (; i < s.size(); ++i) {
        char c = s[i];
        int d;
        if (c >= '0' && c <= '9') d = c - '0';
        else d = c - 'A'  + 10;
        result = result * b + d;
    }

    return result;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int base;
    string n1, n2;
    cin >> base >> n1 >> n2;

    LL sum = stoll(n1, nullptr, base) + stoll(n2, nullptr, base);
    cout << fromBase(sum);

    return 0;
}