Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
168103 C班-赵奕博 K进制数转L进制数 C++ 通过 100 1 MS 248 KB 809 2024-08-19 22:40:27

Tests(5/5):


#include<bits/stdc++.h> using namespace std; string convertBase(int fromBase, int toBase, string number) { int decimalNumber = 0; for (char digit : number) { decimalNumber *= fromBase; decimalNumber += digit >= '0' && digit <= '9'? digit - '0' : digit - 'A' + 10; } string result; while (decimalNumber > 0) { int remainder = decimalNumber % toBase; char digit = remainder < 10? remainder + '0' : remainder - 10 + 'A'; result = digit + result; decimalNumber /= toBase; } return result.empty()? "0" : result; } int main() { int fromBase, toBase; string number; while (cin >> fromBase >> number >> toBase) { cout << convertBase(fromBase, toBase, number) << endl; } return 0; }


测评信息: