Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
167958 李澄 进制数加法 C++ 解答错误 83 0 MS 260 KB 793 2024-08-19 21:18:03

Tests(5/6):


#include <bits/stdc++.h> #include <cstring> using namespace std; string d = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZab"; int main() { int k; string a, b; cin >> k >> a >> b; int p = 1; reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); int ansa = 0, ansb = 0; for (int i = 0; i < a.size(); i++) { if (a[i] >= '0' && a[i] <= '9') ansa += p * (a[i] - 48); else ansa += p * (a[i] - 55); p *= k; } p = 1; for (int i = 0; i < b.size(); i++) { if (b[i] >= '0' && b[i] <= '9') ansb += p * (b[i] - 48); else ansb += p * (b[i] - 55); p *= k; } int ans = ansa + ansb; string sum = ""; while (ans != 0) { sum += d[ans % k]; ans /= k; } for (int i = sum.length() - 1; i >= 0; i--) cout << sum[i]; cout << endl; return 0; }


测评信息: