这个纯粹就是回到小学,算一下竖式,模拟计算过程,推推就好。
Code
#include<bits/stdc++.h>
using namespace std
;
int a
[300],b
[300],c
[300];
string s
;
int main()
{
cin
>>s
;
int len1
=s
.size();
for(int i
=1;i
<=len1
;i
++) a
[i
]=s
[len1
-i
]-'0';
cin
>>s
;
int len2
=s
.size();
for(int i
=1;i
<=len2
;i
++) b
[i
]=s
[len2
-i
]-'0';
int len
=max(len1
,len2
);
int x
=0;
for(int i
=1;i
<=len
;i
++)
{
c
[i
]=x
+a
[i
]+b
[i
];
x
=c
[i
]/10;
c
[i
]%=10;
}
if(x
) c
[++len
]=x
;
for(int i
=len
;i
>=1;i
--) printf("%d",c
[i
]);
return 0;
}
学习厌倦了?点我有更多精彩哦!
转载请注明原文地址: https://mac.8miu.com/read-506371.html