AcWing 3438. 数制转换
原题链接
简单
作者:
sky-koi
,
2024-11-17 20:38:43
,
所有人可见
,
阅读 1
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
typedef long long LL;
vector<int> ve;
int main() {
int a, b;
string n;
cin >> a >> n >> b;
LL res = 0;
for (int i = 0; i < n.size(); i++) {
int x;
if (n[i] >= 'A' && n[i] <= 'Z')
x = n[i] - 'A' + 10;
else if (n[i] >= 'a' && n[i] <= 'z')
x = n[i] - 'a' + 10;
else
x = n[i] - '0';
res += x * pow(a, n.size() - i - 1); // 十进制
}
while (res) {
int x = res % b;
if (x >= 10) {
x = 65 + x - 10;
} else {
x = '0' + x;
}
ve.push_back(x);
res /= b;
}
for (int i = ve.size() - 1; i >= 0; i--) {
cout << (char)ve[i];
}
cout << endl;
return 0;
}