Submission
Status:
PPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: Jibhong
Problemset: บวกเลขฐาน
Language: cpp
Time: 0.003 second
Submitted On: 2026-10-02 21:38:00
#include <bits/stdc++.h>
using namespace std;
int main() {
int base;
string a,b;
cin>>base>>a>>b;
size_t len=max(a.size(),b.size());
len+=1;
/*cout<<'\n'<<a<<'\n'<<b<<'\n';*/
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
while(a.size()<len) a+='0';
while(b.size()<len) b+='0';
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()>1 && a[a.size()-1]=='0'){
a.resize(a.size()-1);
}
reverse(a.begin(),a.end());
cout<<a;
}