3444:【例78.2】大整数加法
[例 78.2] 大整数加法
1168:大整数加法
1168:大整数加法
C++信息学奥赛OJ讲解:1168:大整数加法(高精度加法)
1168:大整数加法
大整数加法(信息学奥赛一本通-T1168)
/*
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 P1064 [NOIP2006 提高组] 金明的预算方案
洛谷 python P1064 [NOIP2006 提高组] 金明的预算方案_洛谷金明的预算方案python-CSDN博客
洛谷 python P1077 [NOIP2012 普及组] 摆花
洛谷 python P1077 [NOIP2012 普及组] 摆花_小明的花店新开张,为了吸引顾客,他想在花店的门口摆上一排花,共 m 盆。通过调查顾-CSDN博客
python:洛谷1085(不高兴的津津)
【洛谷习题】P1093 奖学金
【洛谷-P1106的Python方法】
【洛谷-P1106的Python方法】_python输入两行正整数。 第一行输入一个高精度的正整数 n。 第二行输入一个正整数-CSDN博客
洛谷 python P1115 最大子段和
[洛谷] P1150 Peter的烟 Python