两个任意长度的长整数相乘(华为oj,C++)

这篇博客介绍了一个C++实现的算法,用于计算任意长度的长整数相乘。通过逆序存放乘数并逐位相乘、处理进位的方式,实现了乘法运算。最后将计算结果转换为字符串输出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<pre name="code" class="cpp">#include "oj.h"
#include<iostream>

int main(void)
{
string strMultiplierA = "9999";
string strMultiplierB = "9999";
string strRst = "\0";
multiply (strMultiplierA,strMultiplierB,strRst);
cout << strRst;
return 0;
}

/*****************************************************************************
Prototype    : multiply
Description  : 两个任意长度的长整数相乘, 输出结果
Input pAram  : 
const std::string strMultiplierA  乘数A
const std::string strMultiplierB  乘数B
Output       : 
std::string strRst            乘法结果
Return Value : 
int                       0  正确  
-1  异常
*****************************************************************************/
int multiply (const std::string strMultiplierA,const std::string strMultiplierB, std::string &strRst) 
{

	/* 在这里实现功能 */
	string chengshuA = strMultiplierA;
	string chengshuB = strMultiplierB;
	int a = chengshuA.length();
	int b = chengshuB.length();
	int strRst_length = 0;
	int c = 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值