Submission
Status:
P-----PPP
Subtask/Task Score:
48/100
Score: 48
User: Ricon
Problemset: บวกเลขฐาน
Language: cpp
Time: 0.002 second
Submitted On: 2025-10-06 22:35:17
#include <bits/stdc++.h>
using namespace std;
string decTo(int n, int base) {
if (n == 0) return "0";
string hexChars = "0123456789ABCDEF";
string result = "";
while (n > 0) {
int rem = n % base; // หาเศษ
result = hexChars[rem] + result; // เติมข้างหน้า
n /= base; // หารต่อ
}
return result;
}
int main() {
int base, real1 = 0, real2 = 0;
string num1, num2;
cin >> base >> num1 >> num2;
for (int i = 0; i < num1.length(); i++) {
if (!isdigit(num1[i])) num1[i] -= 7;
real1 += pow(base, num1.length()-i-1) * (int(num1[i]) - '0');
}
for (int i = 0; i < num2.length(); i++) {
if (!isdigit(num1[i])) num1[i] -= 7;
real2 += pow(base, num2.length()-i-1) * (int(num2[i]) - '0');
}
cout << decTo(real1+real2, base);
return 0;
}