https://www.luogu.com.cn/training/117#problems
尝试去复健。今天意外收获ac。
大致思路:将进制转为10进制数后再尝试转成其他进制的数即可。
/*
*/
#include <bits/stdc++.h>
#define debug(x) cout << #x << "=" << x << endl
#define endl '\n'
#define rep(i, a, b) for(int i = a; i <= b; i ++)
using namespace std;
typedef pair<int, int> pii;
using ll = long long;
const int N = 2e5 + 5, INF = 0x3f3f3f3f;
map<int, char> num2char;
map<char, int> char2num;
void init(){
for(int i = 0; i <= 9; i ++){
num2char[i] = (char)(i + '0');
char2num[(char)(i + '0')] = i;
}
for(int i = 10; i <= 15; i ++){
num2char[i] = (char)(i - 10 + 'A');
char2num[(char)(i - 10 + 'A')] = i;
}
}
void solve(){
init();
int a;
cin >> a;
string s;
cin >> s;
int b;
cin >> b;
string ans;
int n10 = 0;
int t = 0;
for(int i = s.size() - 1; i >= 0; i --) {
int now = char2num[s[i]];
n10 += now * pow(a, t ++);
}
while(n10 > 0) {
ans.push_back(num2char[n10 % b]);
n10 /= b;
}
for(int i = ans.size() - 1; i >= 0; i --) cout << ans[i] ;
}
int main(){
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
#ifdef LOCAL
FILE *pPp = fopen("1input.txt", "a+");fclose(pPp);
freopen("1input.txt", "r", stdin);
//freopen("1output.txt", "w", stdout);
#endif
solve();
return 0;
}