#include\x20 #include\x20 using\x20namespace\x20std;

string\x20multiply(string\x20num1,\x20string\x20num2)\x20{ \x20\x20int\x20len1\x20=\x20num1.size(); \x20\x20int\x20len2\x20=\x20num2.size(); \x20\x20int\x20len\x20=\x20len1\x20+\x20len2; \x20\x20int\x20res\x20=\x20new\x20intlen; \x20\x20for\x20(int\x20i\x20=\x20len1\x20-\x201; i\x20>=\x200; i--) \x20\x20{ \x20\x20\x20\x20for\x20(int\x20j\x20=\x20len2\x20-\x201; j\x20>=\x200; j--) \x20\x20\x20\x20{ \x20\x20\x20\x20\x20\x20int\x20n1\x20=\x20num1[i]\x20-\x20'0'; \x20\x20\x20\x20\x20\x20int\x20n2\x20=\x20num2[j]\x20-\x20'0'; \x20\x20\x20\x20\x20\x20res[i\x20+\x20j\x20+\x201]\x20+=\x20n1\x20\x20n2; \x20\x20\x20\x20} \x20\x20} \x20\x20for\x20(int\x20i\x20=\x20len\x20-\x201; i\x20>\x200; i--) \x20\x20{ \x20\x20\x20\x20res[i\x20-\x201]\x20+=\x20res[i]\x20/\x2010; \x20\x20\x20\x20res[i]\x20%=\x2010; \x20\x20} \x20\x20string\x20result\x20=\x20""; \x20\x20int\x20i\x20=\x200; \x20\x20while\x20(i\x20<\x20len\x20&&\x20res[i]\x20==\x200) \x20\x20{ \x20\x20\x20\x20i++; \x20\x20} \x20\x20for\x20(; i\x20<\x20len; i++) \x20\x20{ \x20\x20\x20\x20result\x20+=\x20to_string(res[i]); \x20\x20} \x20\x20delete[]\x20res; \x20\x20return\x20result; }

int\x20main() { \x20\x20string\x20num1,\x20num2; \x20\x20cin\x20>>\x20num1\x20>>\x20num2; \x20\x20string\x20result\x20=\x20multiply(num1,\x20num2); \x20\x20cout\x20<<\x20result\x20<<\x20endl; \x20\x20return\x200; }

C++ 高精度乘法:实现大数相乘算法

原文地址: https://www.cveoy.top/t/topic/pA8G 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录