Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
325108 | 王栎州 | 【C6-3】进制转换 | C++ | 通过 | 100 | 2 MS | 256 KB | 1057 | 2025-06-01 21:46:45 |
#include<bits/stdc++.h> using namespace std; string s; int n, m; string convertToBaseM(int num, int m) { if (num == 0) return "0"; string result = ""; while (num > 0) { int remainder = num % m; char c; if (remainder <= 9) { c = remainder + '0'; } else { c = remainder - 10 + 'A'; } result = c + result; num /= m; } return result; } int convertToDecimal(string num, int base) { int result = 0; for (int i = 0; i < num.length(); i++) { char c = num[i]; int val; if (isdigit(c)) { val = c - '0'; } else { val = (c - 'A') + 10; } result = result * base + val; } return result; } int main() { cin >> n; string input; cin >> input; cin >> m; int decimalValue = convertToDecimal(input, n); string output = convertToBaseM(decimalValue, m); cout << output << endl; return 0; }