愿尔安然无恙


私信TA

用户名:H2130819045

访问量:12475

签 名:

向往星辰大海,喜欢落日晚风。

等  级
排  名 59
经  验 10506
参赛次数 16
文章发表 56
年  龄 20
在职情况 学生
学  校 贺州学院
专  业 软件工程

  自我简介:

不想改bug ^_^

参考代码:

#include <iostream>
#include <cstring>
using namespace std;	
char a[20],b[20];
int aa[20],bb[20],result[20],sum[20];///全局和静态变量默认为0 
int main()
{
	cin>>a>>b;
	int len1=strlen(a);
	int len2=strlen(b);
	for(int i=0;i<len1;i++)
		aa[i]=a[len1-1-i]-'0';//反向保存(从个位开始) 
	for(int j=0;j<len2;j++)
		bb[j]=b[len2-1-j]-'0';////反向保存(从个位开始)
	for(int i=0;i<len1;i++)
	{
		for(int j=0;j<len2;j++)
		{
			sum[i+j]+=aa[i]*bb[j];//i+j,两个相乘位数的代号 
		}
	}
	for(int k=0;k<len1+len2-1;k++)
	{
		result[k]=sum[k];	
	}
	for(int k=0;k<=len1+len2;k++)
		if(result[k]>=10)//需要进位 
		{
			result[k+1]+=result[k]/10;//进位 
			result[k]%=10;
		}	
	int check=len1+len2;
	while(result[check]==0)//若数组(结果)全部为0则会越界,在某一个不确定的check时,不为0 
	{
		check--;
	}
	if(check<0)//因为越界的终点不确定,但终点一定会小于0 
	{
		cout<<0;
	}
	else
	{
		while(check>=0)
		{
			cout<<result[check];//正向输出 
			check--;
		}
	} 
	return 0;
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区