这是题解
2024-09-17 21:43:17
发布于:上海
1阅读
0回复
0点赞
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
string a,b,c;
int as[1000001],bs[1000001],cs[1000001];
memset(as,0,sizeof(as));
memset(cs,0,sizeof(cs));
memset(bs,0,sizeof(bs));
cin >> a >> b;
if((a.size() < b.size())|| ((a.size() == b.size())&& a < b))
{
swap(a,b);
c += '-';
}
int al = a.size(),bl = b.size(),cl = max(a.size(),b.size());
for(int i = 1; i <= al; i++) as[i] = a[al - i] - '0';
for(int i = 1; i <= bl; i++) bs[i] = b[bl - i] - '0';
for(int i = 1; i <= cl; i++)
{
if(as[i] < bs[i])
{
as[i] += 10;
as[i + 1]--;
}
cs[i] = as[i] - bs[i];
}
while(cl > 1 && cs[cl] == 0) cl--;
for(int i = cl; i >= 1; i--) c += cs[i] + '0';
cout << c;
return 0;
}
这里空空如也
有帮助,赞一个