Submission
Status:
------Px-
Subtask/Task Score:
12/100
Score: 12
User: Newton4566
Problemset: บวกเลขฐาน
Language: cpp
Time: 0.002 second
Submitted On: 2026-10-10 15:06:51
#include <bits/stdc++.h>
using namespace std;
string toBase(long long n, int b) {
if (n == 0) return 0;
string digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string s = "";
while (n > 0) {
s = digits[n % b] + s;
n /= b;
}
reverse(s.begin(), s.end());
return s;
}
int main() {
int base;
string n1, n2;
cin >> base >> n1 >> n2;
int sum = stoll(n1, nullptr,base) + stoll(n2, nullptr,base);
cout << toBase(sum, base);
return 0;
}