提交时间:2024-08-19 23:51:16
运行 ID: 168192
#include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; string kToLBase(const string& n, int k, int l) { long long decimalNum = 0; for (int i = 0; i < n.size(); ++i) { decimalNum = decimalNum * k + (n[i] >= '0' && n[i] <= '9' ? n[i] - '0' : n[i] - 'a' + 10); } string lBaseNum = ""; while (decimalNum > 0) { int remainder = decimalNum % l; char digit = remainder < 10 ? '0' + remainder : 'a' + (remainder - 10); lBaseNum = digit + lBaseNum; decimalNum /= l; } if (lBaseNum.empty()) { return "0"; } return lBaseNum; } int main() { string n; int k,l; while (cin >> n >> k >> l) { cout<<kToLBase(n,k,l); } return 0; }