提交时间:2024-08-19 23:14:39

运行 ID: 168163

#include <bits/stdc++.h> using namespace std; const int MAXN = 500; int main() { int base, tbase; char n[MAXN]; while (cin >> base >> n >> tbase) { int len = strlen(n); long long v10 = 0; for (int i = len - 1, power = 1; i >= 0; i--, power *= base) { if (isdigit(n[i])) { v10 += (n[i] - '0') * power; } else if (isalpha(n[i])) { v10 += (tolower(n[i]) - 'a' + 10) * power; } } if (v10 == 0) { cout << '0'; } else { vector<char> res; while (v10 > 0) { int r = v10 % tbase; if (r < 10) { res.push_back('0' + r); } else { res.push_back('A' + r - 10); } v10 /= tbase; } reverse(res.begin(), res.end()); for (char c : res) { cout << c; } } cout << endl; } return 0; }