Submission

Status:

-------P-

Subtask/Task Score:

12/100

Score: 12

User: Buslnwzuz

Problemset: บวกเลขฐาน

Language: cpp

Time: 0.002 second

Submitted On: 2026-10-11 21:03:52

#include <bits/stdc++.h>
using namespace std;
int toten(string a,int base){
    int ch=0;
    int 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; 
    int total = toten(num_1,base) + toten(num_2,base);
    cout << total << endl;
    vector<char> ans;
    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;
}