洛谷P1601 题解

传送门
这道题其实就是模板题,套高精度模板就好了
代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a1[1000],b1[1000];//因为输的数大,所以用char
	int a[1000],b[1000],c[1000]={0};//输入后转换
	cin >> a1 >> b1;
	int s1=strlen(a1);
	int s2=strlen(b1);
	int s3;
	//转换开始
	for(int i=0;i<s1;i++)
	{
		a[s1-i]=a1[i]-'0';
	}
	for(int i=0;i<s2;i++)
	{
		b[s2-i]=b1[i]-'0';
	}
	//开始计算
	s3=1;
	int x=0;
	while(s3<=s1 || s3<=s2)
	{
		c[s3]=a[s3]+b[s3]+x+c[s3];
		x=c[s3]/10;
		c[s3]=c[s3]%10;
		s3++;
	}
	c[s3]=x;//有可能有进位
	if(c[s3]==0)
	{
		s3--;//退位
	}
	for(int i=s3;i>=1;i--)
	{
		cout << c[i];//因为前面倒着载入,所以倒着输出
	}
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值