基础数学问题 P1143 进制转换
题目
https://www.luogu.com.cn/problem/P1143
代码
#include<iostream> #include<cmath> #include<string> #include<cstring> using namespace std; int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); int n, m; string tmp; long long num = 0; cin >> n >> tmp >> m; for (int i = 0; i < tmp.length(); i++) { if (isupper(tmp[i]))num = num + (tmp[i] - 'A' + 10)*pow(n, tmp.length() - i - 1); if(isdigit(tmp[i]))num=num+(tmp[i]-'0')*pow(n, tmp.length() - i - 1); } int list[50000]; int cnt = 0; while (num) { list[cnt++] = num % m; num /= m; } for (int i = cnt-1; i >=0; i--)//注意这里的顺序 { if (list[i] < 10) cout << list[i]; else cout << (char)(list[i] - 10 + 'A'); } }