3444:【例78.2】大整数加法

3444:【例78.2】大整数加法

信息学奥赛一本通-编程启蒙(C++版)在线评测系统

[例 78.2] 大整数加法

1168:大整数加法

信息学奥赛一本通(C++版)在线评测系统

1168:大整数加法

1168:大整数加法_哔哩哔哩_bilibili

C++信息学奥赛OJ讲解:1168:大整数加法(高精度加法)

C++信息学奥赛OJ讲解:1168:大整数加法(高精度加法)_哔哩哔哩_bilibili

1168:大整数加法

1168:大整数加法_哔哩哔哩_bilibili

大整数加法(信息学奥赛一本通-T1168)

大整数加法(信息学奥赛一本通-T1168)_哔哩哔哩_bilibili




/*
1168:大整数加法
http://ybt.ssoier.cn:8088/problem_show.php?pid=1168

P1601 A+B Problem(高精)
https://www.luogu.com.cn/problem/P1601

1.6编程基础之一维数组 10:大整数加法
http://noi.openjudge.cn/ch0106/10/
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <bits/stdc++.h> 
using namespace std;
int main( void )
{
	//char a1[300],b1[300];
	
	string a1,b1;
	
	int a[300],b[300],c[300],lena,lenb,lenc,i,x;
	
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	memset(c,0,sizeof(c));
	
	//输入加数与被加数
	//gets(a1);
	//gets(b1);
	
	cin>>a1;
	cin>>b1;
	                                         
	lena=a1.length();
	lenb=b1.length();
	
	//将输入字符串倒置
	//加数放入a数组 
	for (i=0;i<=lena-1;i++) a[lena-i]=a1[i]-48;    
	/*
	//加数放入a数组
	for (i=0;i<=lena-1;i++) a[lena-i]=a1[i]-'0';    
	*/
	
	//加数放入b数组
	for (i=0;i<=lenb-1;i++) b[lenb-i]=b1[i]-48;    
	
	lenc =1;
	x=0;
	while ( lenc <=lena || lenc <=lenb )
	{
		//两数相加
		c[lenc]=a[lenc]+b[lenc]+x;     
		x=c[lenc]/10;
		c[lenc]%=10;
	    lenc++;
	}
	c[lenc]=x; 
	
	//去掉多余的0
	while(c[lenc]==0 && lenc>1)   
	{
		lenc--;
	}
	/*
	//处理最高进位
	if (c[lenc]==0)
		lenc--;                                    
	*/
	
	//输出结果
	for (i=lenc;i>=1;i--) 
		cout<<c[i];                            
	
	cout<<endl;
	
	return 0;
}


/*
1.6编程基础之一维数组 10大整数加法(AC)-2022.08.11 运算符重载 
http://noi.openjudge.cn/ch0106/10/
*/
#include <algorithm>
#include <iostream>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <cctype>
#include <vector>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
const int maxn=201;
struct bignumber
{
	int len,s[maxn];
	bignumber(){memset(s,0,sizeof(s));len=1;}
	bignumber operator = (const char* num)
{
	len=strlen(num);
	for(int i=0;i<len;i++)s[i]=num[len-i-1]-'0';
	return *this;
}
bignumber operator = (const int num)
{
	char a[maxn];
	sprintf(a,"%d",num);
	*this=a;
	return *this;
}
bignumber (const int num){*this=num;}
bignumber (const char* num){*this=num;}
bignumber operator+(const bignumber& a)
{
	bignumber c;
	c.len=max(len,a.len)+1;
	for(int i=0,x=0;i<c.len;i++)
	{
		c.s[i]=s[i]+a.s[i]+x;
		x=c.s[i]/10;
		c.s[i]=c.s[i]%10;
	}
	while(c.s[c.len-1]==0&&c.len>1)c.len--;
	return c;
}
bool operator < (const bignumber& x)const
{
	if(len!=x.len)return len<x.len;
	for(int i=len-1;i>=0;i--)if(s[i]!=x.s[i])return s[i]<x.s[i];
	return false;
}
};
ostream& operator<<(ostream& out,const bignumber &x)
{
	for(int i=x.len-1;i>=0;i--)cout<<x.s[i];
	return out;
}
istream& operator>>(istream& in,bignumber &x)
{
	char num[maxn];
	in>>num;
	x=num;
	return in;
}
bignumber a,b;
int main()
{
	ios::sync_with_stdio(false);
	cin>>a>>b;
	cout<<a+b<<endl;
	return 0;
}



 




python:1046(摘苹果)

python:1046(摘苹果)_p1046落谷python-CSDN博客

P1046洛谷 Python题解_洛谷的python答案-CSDN博客

洛谷 python P1064 [NOIP2006 提高组] 金明的预算方案

洛谷 python P1064 [NOIP2006 提高组] 金明的预算方案_洛谷金明的预算方案python-CSDN博客

洛谷 python P1077 [NOIP2012 普及组] 摆花

洛谷 python P1077 [NOIP2012 普及组] 摆花_小明的花店新开张,为了吸引顾客,他想在花店的门口摆上一排花,共 m 盆。通过调查顾-CSDN博客

python:洛谷1085(不高兴的津津)

python:洛谷1085(不高兴的津津)_python不高兴的津津-CSDN博客

【洛谷习题】P1093 奖学金

【洛谷习题】P1093 奖学金_python 洛谷 p1093-CSDN博客

【洛谷-P1106的Python方法】

【洛谷-P1106的Python方法】_python输入两行正整数。 第一行输入一个高精度的正整数 n。 第二行输入一个正整数-CSDN博客

洛谷 python P1115 最大子段和

洛谷 python P1115 最大子段和_pythonp1115 最大子段和-CSDN博客

[洛谷] P1150 Peter的烟 Python

[洛谷] P1150 Peter的烟 Python_洛谷p1150-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dllglvzhenfeng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值