题解
2024-09-04 23:23:06
发布于:上海
4阅读
0回复
0点赞
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
int main()
{
string n,m,ans;
cin >> m >> n;
int ml = m.size(),nl = n.size();
int num1[1000001],numsum[1000001],num2[1000002];
memset(num1,0,sizeof(num1));
memset(num2,0,sizeof(num2));
memset(numsum,0,sizeof(numsum));
while(m[ml] == '0' && ml > 1) ml--;
while(n[nl] == '0' && nl > 1) nl--;
for(int i = 1; i <= ml; i++)num1[i] = m[ml - i] - '0';
for(int i = 1; i <= nl; i++)num2[i] = n[nl - i] - '0';
int maxlen = max(nl,ml)+ 1;
for(int i = 1; i <= maxlen; i++)
{
numsum[i] += num2[i] + num1[i];
numsum[i + 1] += numsum[i] / 10;
numsum[i] %= 10;
}
if(numsum[maxlen] == 0) maxlen--;//注意第十个测试点要输出前导0
for(int i = maxlen; i >= 1; i--) ans += numsum[i] + '0';
cout << ans;
}
这里空空如也
有帮助,赞一个