Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
180659 C班—刘铠锋 进制数加法 C++ 无测评数据 0 0 MS 0 KB 972 2024-08-21 17:11:22

Tests(0/0):


#include <bits/stdc++.h> using namespace std; long long convertToDecimal(const string& number, int base) { long long result = 0; for (int i = 0; i < number.size(); i++) { char digit = number[number.size() - 1 - i]; if (isdigit(digit)) { result += (digit - '0') * pow(base, i); } else { result += (toupper(digit) - 'A' + 10) * pow(base, i); } } return result; } string convertToBase(long long decimal, int base) { if (decimal == 0) return "0"; string result; while (decimal > 0) { int remainder = decimal % base; if (remainder < 10) { result += (remainder + '0'); } else { result += (remainder - 10 + 'A'); } decimal /= base; } reverse(result.begin(), result.end()); return result; } int main() { int N; string num1, num2; cin >> N >> num1 >> num2; long long dec1 = convertToDecimal(num1, N); long long dec2 = convertToDecimal(num2, N); long long sum = dec1 + dec2; string result = convertToBase(sum, N); cout << result; return 0; }