Submission

Status:

PPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: IKKIWPR

Problemset: บวกเลขฐาน

Language: cpp

Time: 0.005 second

Submitted On: 2026-10-13 16:26:07

#include <bits/stdc++.h>
using namespace std;
long long toten(string a,int base){
    int ch=0;
    long long total = 0;
    for(char num:a){
        if(num>='0'&&num<='9'){
            ch = num-'0';
        }
        else if(num>='A'&&num<='F'){
            ch = num - 'A' + 10;
        }
        total = total*base + ch;
    }
    return total;
}

int main(){
    int base;
    cin >> base;
    string num_1,num_2;
    cin >> num_1 >> num_2; 
    long long total = toten(num_1,base) + toten(num_2,base);
    vector<char> ans;
    if(total == 0) {
        cout << 0;
        return 0;
    }
    while(total > 0){
        int it = total%base;
        char ch;
        if(it>=0&&it<=9){
            ch = '0' +it;
            ans.push_back(ch);
        }
        else{
            ch = (it-10) + 'A';
            ans.push_back(ch);
        }
        total/=base;
    }
    reverse(ans.begin(),ans.end());
    for(char num:ans){
        cout << num;
    }
    return 0;
}