Submission

Status:

PPPPPPP-P

Subtask/Task Score:

96/100

Score: 96

User: Jibhong

Problemset: บวกเลขฐาน

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-02 20:50:46

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

int main() {
    int base;
    string a,b;
    cin>>base>>a>>b;
    string out="";
    size_t len=max(a.size(),b.size());
    len+=1;
    while(a.size()<len) a.insert(0,1,'0');
    while(b.size()<len) b.insert(0,1,'0');
    /*cout<<'\n'<<a<<'\n'<<b<<'\n';*/
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    int before=0;
    for(int i=0;i<len;++i){
        int A=a[i]-'0';
        int B=b[i]-'0';
        if(A>9)A=a[i]-'A'+10;
        if(B>9)B=b[i]-'A'+10;
        int now=before+A+B;
        before=now/base;
        now%=base;
        if(now>9)a[i]=now-10+'A';
        else a[i]=now+'0';
    }
    while(a.size()>0 && a[a.size()-1]=='0'){
        a.resize(a.size()-1);
    }
    reverse(a.begin(),a.end());
    cout<<a;
}