Submission

Status:

PPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: polikanta

Problemset: บวกเลขฐาน

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-12 22:23:48

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

int main() {
    int n;
    cin >> n;
    string a,b;
    cin >> a >> b;

    int m1 = 0;
    int m2 = 0;
    for(char c : a) {
        if (c >= 'A' && c <= 'Z') {
            m1 = m1*n;
            m1 += c-'A'+10;
        }else {
            m1 = m1 * n;
            m1 += c-'0';
        }
    }
    for(char c : b) {
        if (c >= 'A' && c <= 'Z') {
            m2 = m2*n;
            m2 += c-'A'+10;
        }else {
            m2 = m2 * n;
            m2 += c-'0';
        }
    }
    int M = m1 + m2;

    if (M == 0) {
        cout << "0";
        return 0;
    }
    string num = "";
    while (M > 0) {
        if(M % n > 9){
            num = (char)(M%n-10+'A') + num;
        }else {
            num = (char)(M%n + '0') + num;
        }
        M = M/n;
    }
    cout << num;
}