Submission
Status:
PPPPPPP-P
Subtask/Task Score:
96/100
Score: 96
User: letdown
Problemset: บวกเลขฐาน
Language: cpp
Time: 0.002 second
Submitted On: 2025-10-06 16:11:29
#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;
int main() {
int b, lx, ly, s;
string x,y,ans;
cin>>b>>x>>y;
int decx=0, decy=0;
for (int i = 0; i < x.length(); i++) {
int idx = x.length()-i-1, d;
if (x[idx] <= '9') d = (x[idx] - '0');
else d = (x[idx] - 'A' + 10);
decx += d*pow(b, i);
}
for (int i = 0; i < y.length(); i++) {
int idy = y.length()-i-1, d;
if (y[idy] <= '9') d = (y[idy] - '0');
else d = (y[idy] - 'A' + 10);
decy += d*pow(b, i);
}
s = decx + decy;
while (s > 0) {
int d = s % b;
s /= b;
if (d <= 9) ans += char(d + '0');
else ans += char(d + 'A' - 10);
}
for (int i = 0; i < ans.length()/2; i++) {
char t = ans[i];
ans[i] = ans[ans.length() - i - 1];
ans[ans.length() - i - 1] = t;
}
cout << ans;
}