高精度加法

高精度加法

include

include

include

include

include

include

include

include

include

define MAXN 0x3f3f3f3f

using namespace std;
int main()
{
long long a1[10000];
string a;
string b;
int t = 0;
cin >> a >> b;
int str1 = a.size();
int str2 = b.size();
while(str1!=0||str2!=0)
{
if(str10)
{
a1[t]+=b[--str2] - '0';//反向粗存
}
else if(str2
0)
{
a1[t] += a[--str1]-'0';
}
else{
a1[t] += a[--str1]-'0';
a1[t] += b[--str2] - '0';}
if(a1[t]/10!=0)//进位
{
a1[t + 1]++;
a1[t] = a1[t] % 10;
}
t++;
}
while(t>0&&a1[t]==0)//除去前导0
{
t--;
}
for (int i = t; i>= 0;i--)
{ cout << a1[i];}
return 0;
}

原文地址:https://www.cnblogs.com/a821403286/p/13693333.html