提交时间:2024-08-19 21:58:59
运行 ID: 168036
#include <iostream> #include <cmath> using namespace std; int main() { int w, n; char s[500]; while (cin >> w >> s >> n) { int len = strlen(s), p = 0, ans = 0; for (int i = len - 1; i >= 0; i--) { if (s[i] >= 'a' && s[i] <= 'z') { ans += (s[i] - 'a' + 10) * pow(w, p); } else if (s[i] >= 'A' && s[i] <= 'Z') { ans += (s[i] - 'A' + 10) * pow(w, p); } else if (s[i] >= '0' && s[i] <= '9') { ans += (s[i] - '0') * pow(w, p); } p++; } int l = 0; while (ans!= 0) { a[++l] = ans % n; ans /= n; } for (int i = l; i >= 1; i--) { if (a[i] >= 10) { char h = 'A'; h += a[i] - 10; cout << h; } else { cout << a[i]; } } cout << endl; } return 0; }