Submission
Status:
P-P--PP-P
Subtask/Task Score:
60/100
Score: 60
User: kodpungtu
Problemset: บวกเลขฐาน
Language: cpp
Time: 0.003 second
Submitted On: 2025-10-02 16:19:21
#include <bits/stdc++.h>
using namespace std;
int toDec(int b, string s) {
int dec = 0;
for (int i = s.length() -1; i >= 0; i--) {
if (s[i] < '9') {
dec += int(s[i] - '0') * pow(b, s.length() - i - 1);
} else {
dec += int(s[i] - 'A' + 10) * pow(b, s.length() - i - 1);
}
}
return dec;
}
string toBase(int b, int num) {
string ans = "";
int n = num;
while (n > 0) {
int d = n % b;
n /= b;
if (d < 9) {
ans += to_string(d);
} else {
ans += char(d + 'A' - 10);
}
}
reverse(ans.begin(), ans.end());
return ans;
}
int main() {
int base;
string x, y;
cin >> base >> x >> y;
cout << toBase(base, toDec(base, x) + toDec(base, y));
}