提交时间:2024-08-19 23:09:58

运行 ID: 168153

#include <bits/stdc++.h> using namespace std; const int MAXN = 500; int main() { int base, base; char n[MAXN]; while (cin >> base >> n >> base) { 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 % base; if (r < 10) { res.push_back('0' + r); } else { res.push_back('A' + r - 10); } v10 /= base; } reverse(res.begin(), res.end()); for (char c : res) { cout << c; } } cout << endl; } return 0; }