Submission
Status:
PPPPPPPPP
Score: 100
User: Namkhing
Problemset: บวกเลขฐาน
Language: cpp
Time: 0.002 second
Submitted On: 2025-04-10 21:39:24
#include <bits/stdc++.h>
using namespace std;
int solve(string s, int k) {
int res = 0;
for (char c : s) {
int val;
if ('A' <= c && c <= 'Z') val = 10 + c - 'A';
else val = c - '0';
res = res * k + val;
}
return res;
}
string solve(int n, int k) {
string s = "";
while (n > 0) {
int val = n % k;
char add;
if (val < 10) add = '0' + val;
else add = 'A' + val - 10;
s.push_back(add);
n /= k;
}
if (s.empty()) s.push_back('0');
reverse(s.begin(), s.end());
return s;
}
int main() {
cin.tie(nullptr)->ios_base::sync_with_stdio(false);
int k;
cin >> k;
string a, b;
cin >> a >> b;
int A = solve(a, k);
int B = solve(b, k);
cout << solve(A + B, k);
}