文章
79
粉丝
221
获赞
46
访问
196.6k
#include <iostream>
#include <string>
using namespace std;
string Sul(string a, int m, int n) {
long long sum = 0;
string res = "";
for (int i = 0; i < a.size(); i++) {
if (a[i] >= '0' && a[i] <= '9')
sum = sum*m+(a[i] - '0');
else
sum = sum*m+(a[i] - 'A' + 10);
}
if (sum == 0)
return "0";
while (sum > 0) {
if (sum % n < 10)
res = char(sum % n + '0') + res;
else
res = char(sum % n - 10 + 'a') + res;
sum /= n;
}
return res;
}
int main() {
int m, n;
cin >> m >> n;
string s;
cin >> s;
cout << Sul(s, m, n) << endl;
return 0;
}
注:m进制转10进制时一定要从前往后加和,和每次乘以进制数。
登录后发布评论
暂无评论,来抢沙发