#include<cstdio>
#include<cstring>
using namespace std;
struct sd {
int lend,d[
300];
sd(){
memset(d,
0,
sizeof(d));}
sd
operator + (
const sd &x)
const {
sd c;
int t=lend>x.lend?lend:x.lend;
c.d[
0]=
0;
for (
int i=
0;i<t;i++)
{
c.d[i]=c.d[i]+d[i]+x.d[i];
c.d[i+
1]=c.d[i]/
10;
c.d[i]=c.d[i] %
10;
}
c.lend=t;
if (c.d[t]>
0) c.lend++;
return c;
}
};
sd readit()
{
sd c;
char st[
300];
scanf(
"%s",st);
int j=
0;
for (
int i=
strlen(st)-
1;i>=
0;i--)
{
c.d[j]=st[i]-
48;j++;
}
c.lend=j;
return c;
}
int main()
{
sd a,b,c;
a=readit();b=readit();
c=a+b;
for (
int i=c.lend-
1;i>=
0;i--)
printf(
"%d",c.d[i]);
printf(
"\n");
return 0;
}
核心: 结构体,运算符重载,倒序存入
转载请注明原文地址: https://ju.6miu.com/read-18120.html