From e0ed0de4f4bad95a826c276f9514199c88314e74 Mon Sep 17 00:00:00 2001 From: fdzcxy212206260 <1185490104@qq.com> Date: Thu, 10 Oct 2024 15:08:51 +0800 Subject: [PATCH] Delete 'zuoye.cpp' --- zuoye.cpp | 47 ----------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 zuoye.cpp diff --git a/zuoye.cpp b/zuoye.cpp deleted file mode 100644 index 64a91a4..0000000 --- a/zuoye.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include -#include - -int toDecimal(const std::string& num, int base) { - int decimalValue = 0; - for (char digit : num) { - decimalValue *= base; - decimalValue += (isdigit(digit) ? digit - '0' : digit - 'A' + 10); - } - return decimalValue; -} - -std::string fromDecimal(int decimalValue, int base) { - if (decimalValue == 0) return "0"; - - std::string result; - while (decimalValue > 0) { - int remainder = decimalValue % base; - result += (remainder < 10 ? '0' + remainder : 'A' + (remainder - 10)); - decimalValue /= base; - } - std::reverse(result.begin(), result.end()); - return result; -} - -std::string convertBase(const std::string& num, int fromBase, int toBase) { - return fromDecimal(toDecimal(num, fromBase), toBase); -} - -int main() { - std::string number; - int fromBase, toBase; - - std::cout << "输入数字:"; - std::cin >> number; - std::cout << "输入源进制(2-16):"; - std::cin >> fromBase; - std::cout << "输入目标进制(2-16):"; - std::cin >> toBase; - - std::string convertedNumber = convertBase(number, fromBase, toBase); - std::cout << "转换后的数字是:" << convertedNumber << std::endl; - - return 0; -}