#include \n#include \n#include \n\nstruct HighPrecisionFloat {\n std::vector integerPart; // 整数部分\n std::vector decimalPart; // 小数部分\n int decimalPlaces; // 小数位数\n\n HighPrecisionFloat() {\n decimalPlaces = 6; // 默认小数位数为6\n }\n\n HighPrecisionFloat(std::string numStr) {\n decimalPlaces = 6;\n parseString(numStr);\n }\n\n void parseString(std::string numStr) {\n // 解析整数部分\n size_t integerEnd = numStr.find('.');\n if (integerEnd == std::string::npos) {\n integerPart.push_back(std::stoi(numStr));\n } else {\n std::string integerStr = numStr.substr(0, integerEnd);\n for (int i = integerStr.length() - 1; i >= 0; i--) {\n integerPart.push_back(integerStr[i] - '0');\n }\n\n // 解析小数部分\n std::string decimalStr = numStr.substr(integerEnd + 1);\n for (int i = 0; i < decimalStr.length(); i++) {\n decimalPart.push_back(decimalStr[i] - '0');\n }\n }\n }\n\n std::string toString() {\n std::string result = "";\n // 整数部分\n for (int i = integerPart.size() - 1; i >= 0; i--) {\n result += std::to_string(integerPart[i]);\n }\n // 小数部分\n if (!decimalPart.empty()) {\n result += ".";\n for (int i = 0; i < decimalPart.size(); i++) {\n result += std::to_string(decimalPart[i]);\n }\n }\n return result;\n }\n\n HighPrecisionFloat operator+(const HighPrecisionFloat& other) const {\n HighPrecisionFloat result;\n int carry = 0;\n int maxDecimalPlaces = std::max(decimalPlaces, other.decimalPlaces);\n // 将两个浮点数的小数部分对齐\n std::vector alignedDecimalPart1 = decimalPart;\n std::vector alignedDecimalPart2 = other.decimalPart;\n while (alignedDecimalPart1.size() < maxDecimalPlaces) {\n alignedDecimalPart1.push_back(0);\n }\n while (alignedDecimalPart2.size() < maxDecimalPlaces) {\n alignedDecimalPart2.push_back(0);\n }\n\n // 小数部分相加\n for (int i = 0; i < maxDecimalPlaces; i++) {\n int sum = alignedDecimalPart1[i] + alignedDecimalPart2[i] + carry;\n result.decimalPart.push_back(sum % 10);\n carry = sum / 10;\n }\n\n // 整数部分相加\n int maxLength = std::max(integerPart.size(), other.integerPart.size());\n for (int i = 0; i < maxLength; i++) {\n int sum = (i < integerPart.size() ? integerPart[i] : 0)\n + (i < other.integerPart.size() ? other.integerPart[i] : 0)\n + carry;\n result.integerPart.push_back(sum % 10);\n carry = sum / 10;\n }\n if (carry > 0) {\n result.integerPart.push_back(carry);\n }\n\n return result;\n }\n\n HighPrecisionFloat operator-(const HighPrecisionFloat& other) const {\n HighPrecisionFloat result;\n int borrow = 0;\n int maxDecimalPlaces = std::max(decimalPlaces, other.decimalPlaces);\n // 将两个浮点数的小数部分对齐\n std::vector alignedDecimalPart1 = decimalPart;\n std::vector alignedDecimalPart2 = other.decimalPart;\n while (alignedDecimalPart1.size() < maxDecimalPlaces) {\n alignedDecimalPart1.push_back(0);\n }\n while (alignedDecimalPart2.size() < maxDecimalPlaces) {\n alignedDecimalPart2.push_back(0);\n }\n\n // 小数部分相减\n for (int i = 0; i < maxDecimalPlaces; i++) {\n int diff = alignedDecimalPart1[i] - alignedDecimalPart2[i] - borrow;\n if (diff < 0) {\n diff += 10;\n borrow = 1;\n } else {\n borrow = 0;\n }\n result.decimalPart.push_back(diff);\n }\n\n // 整数部分相减\n int maxLength = std::max(integerPart.size(), other.integerPart.size());\n for (int i = 0; i < maxLength; i++) {\n int diff = (i < integerPart.size() ? integerPart[i] : 0)\n - (i < other.integerPart.size() ? other.integerPart[i] : 0)\n - borrow;\n if (diff < 0) {\n diff += 10;\n borrow = 1;\n } else {\n borrow = 0;\n }\n result.integerPart.push_back(diff);\n }\n while (result.integerPart.size() > 1 && result.integerPart.back() == 0) {\n result.integerPart.pop_back();\n }\n\n return result;\n }\n\n HighPrecisionFloat operator*(const HighPrecisionFloat& other) const {\n HighPrecisionFloat result;\n int maxDecimalPlaces = decimalPlaces + other.decimalPlaces;\n result.decimalPlaces = maxDecimalPlaces;\n\n // 小数部分相乘\n std::vector tempDecimalPart(maxDecimalPlaces, 0);\n for (int i = 0; i < decimalPart.size(); i++) {\n for (int j = 0; j < other.decimalPart.size(); j++) {\n tempDecimalPart[i + j] += decimalPart[i] * other.decimalPart[j];\n }\n }\n\n // 处理小数部分的进位\n int carry = 0;\n for (int i = 0; i < maxDecimalPlaces; i++) {\n int sum = tempDecimalPart[i] + carry;\n result.decimalPart.push_back(sum % 10);\n carry = sum / 10;\n }\n\n // 整数部分相乘\n std::vector tempIntegerPart(integerPart.size() + other.integerPart.size(), 0);\n for (int i = 0; i < integerPart.size(); i++) {\n for (int j = 0; j < other.integerPart.size(); j++) {\n tempIntegerPart[i + j] += integerPart[i] * other.integerPart[j];\n }\n }\n\n // 处理整数部分的进位\n carry = 0;\n for (int i = 0; i < tempIntegerPart.size(); i++) {\n int sum = tempIntegerPart[i] + carry;\n result.integerPart.push_back(sum % 10);\n carry = sum / 10;\n }\n while (result.integerPart.size() > 1 && result.integerPart.back() == 0) {\n result.integerPart.pop_back();\n }\n\n return result;\n }\n\n HighPrecisionFloat operator/(const HighPrecisionFloat& other) const {\n if (other.integerPart.size() == 1 && other.integerPart[0] == 0 && other.decimalPart.empty()) {\n throw std::runtime_error("Divide by zero");\n }\n\n HighPrecisionFloat result;\n int maxDecimalPlaces = decimalPlaces + other.decimalPlaces;\n result.decimalPlaces = maxDecimalPlaces;\n\n // 小数部分相除\n std::vector tempDecimalPart(maxDecimalPlaces, 0);\n for (int i = 0; i < decimalPart.size(); i++) {\n for (int j = 0; j < maxDecimalPlaces; j++) {\n if (j < other.decimalPart.size()) {\n tempDecimalPart[i + j] += decimalPart[i] / other.decimalPart[j];\n } else {\n tempDecimalPart[i + j] += decimalPart[i] / 1; // 补0进行除法\n }\n }\n }\n\n // 处理小数部分的进位\n int carry = 0;\n for (int i = maxDecimalPlaces - 1; i >= 0; i--) {\n int quotient = (tempDecimalPart[i] + carry) / 10;\n carry = (tempDecimalPart[i] + carry) % 10;\n result.decimalPart.insert(result.decimalPart.begin(), carry);\n carry = quotient;\n }\n\n // 整数部分相除\n std::vector tempIntegerPart(integerPart.size(), 0);\n for (int i = 0; i < integerPart.size(); i++) {\n for (int j = 0; j < other.integerPart.size(); j++) {\n if (j < other.integerPart.size()) {\n tempIntegerPart[i + j] += integerPart[i] / other.integerPart[j];\n } else {\n tempIntegerPart[i + j] += integerPart[i] / 1; // 补0进行除法\n }\n }\n }\n\n // 处理整数部分的进位\n carry = 0;\n for (int i = tempIntegerPart.size() - 1; i >= 0; i--) {\n int quotient = (tempIntegerPart[i] + carry) / 10;\n carry = (tempIntegerPart[i] + carry) % 10;\n result.integerPart.insert(result.integerPart.begin(), carry);\n carry = quotient;\n }\n while (result.integerPart.size() > 1 && result.integerPart.back() == 0) {\n result.integerPart.pop_back();\n }\n\n return result;\n }\n\n HighPrecisionFloat& operator+=(const HighPrecisionFloat& other) {\n *this = *this + other;\n return *this;\n }\n\n HighPrecisionFloat& operator-=(const HighPrecisionFloat& other) {\n *this = *this - other;\n return this;\n }\n\n HighPrecisionFloat& operator=(const HighPrecisionFloat& other) {\n *this = *this * other;\n return *this;\n }\n\n HighPrecisionFloat& operator/=(const HighPrecisionFloat& other) {\n *this = *this / other;\n return *this;\n }\n};\n\n// 测试代码\nint main() {\n HighPrecisionFloat a("123.456");\n HighPrecisionFloat b("789.012");\n std::cout << "a = " << a.toString() << std::endl;\n std::cout << "b = " << b.toString() << std::endl;\n\n HighPrecisionFloat c = a + b;\n std::cout << "a + b = " << c.toString() << std::endl;\n\n HighPrecisionFloat d = a - b;\n std::cout << "a - b = " << d.toString() << std::endl;\n\n HighPrecisionFloat e = a * b;\n std::cout << "a * b = " << e.toString() << std::endl;\n\n HighPrecisionFloat f = a / b;\n std::cout << "a / b = " << f.toString() << std::endl;\n\n a += b;\n std::cout << "a += b: a = " << a.toString() << std::endl;\n\n a -= b;\n std::cout << "a -= b: a = " << a.toString() << std::endl;\n\n a *= b;\n std::cout << "a *= b: a = " << a.toString() << std::endl;\n\n a /= b;\n std::cout << "a /= b: a = " << a.toString() << std::endl;\n\n return 0;\n