Submission
Status:
PPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: RandomPerson
Problemset: บวกเลขฐาน
Language: cpp
Time: 0.002 second
Submitted On: 2025-10-12 21:02:52
#include <iostream>
using namespace std;
int main() {
int x,c;
char ans[10000]={0};
string y,z;
cin >> x >> y >> z;
for (int i=0;y[i]!='\0';i++) {
if (y[i]=='A') {
y[i]=10;
}
else if (y[i]=='B') {
y[i]=11;
}
else if (y[i]=='C') {
y[i]=12;
}
else if (y[i]=='D') {
y[i]=13;
}
else if (y[i]=='E') {
y[i]=14;
}
else if (y[i]=='F') {
y[i]=15;
}
else {
y[i]-=48;
}
}
for (int i=0;z[i]!='\0';i++) {
if (z[i]=='A') {
z[i]=10;
}
else if (z[i]=='B') {
z[i]=11;
}
else if (z[i]=='C') {
z[i]=12;
}
else if (z[i]=='D') {
z[i]=13;
}
else if (z[i]=='E') {
z[i]=14;
}
else if (z[i]=='F') {
z[i]=15;
}
else {
z[i]-=48;
}
}
if (y.length()>=z.length()) {
c=y.length();
}
else if (y.length()<z.length()) {
c=z.length();
}
for (int i=0;i<c;i++) {
int y1=0,z1=0;
if(y.length()-1-i>=0)y1=y[y.length()-1-i];
else y1=0;
if(z.length()-1-i>=0)z1=z[z.length()-1-i];
else z1=0;
ans[c-i]+=y1+z1;
if(ans[c-i]>=x){
ans[c-i]-=x;
ans[c-i-1]=1;
}
}
for (int i=0;i<=c;i++){
if(i==0 && ans[0]==0);
else if(i==0) cout << 1;
else{
if (ans[i]<10)cout << int(ans[i]);
else if (ans[i]==10){
cout << 'A';
}
else if (ans[i]==11){
cout << 'B';
}
else if (ans[i]==12){
cout << 'C';
}
else if (ans[i]==13){
cout << 'D';
}
else if (ans[i]==14){
cout << 'E';
}
else {
cout << 'F';
}
}
}
return 0;
}