题解
2025-02-23 12:08:33
发布于:浙江
2阅读
0回复
0点赞
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
const int N=10005;
string s1,s2;
int x[N],y[N],z[N];
void f(string s,int h[])
{
h[0]=s.size();
for(int i=1;i<=h[0];i++)
{
h[i]=s[h[0]-i]-'0';
}
}
void sub(int a[],int b[],int c[])
{
c[0]=a[0];
for(int i=1;i<=c[0];i++)
{
if(a[i]<b[i])
{
a[i]+=10;
a[i+1]-=1;
}
c[i]=a[i]-b[i];
}
while(c[c[0]]==0 && c[0]>1)
{
c[0]--;
}
}
void p(int h[])
{
for(int i=h[0];i>=1;i--)
{
cout<<h[i];
}
}
int main(){
cin>>s1;
cin>>s2;
if(s1.length()<s2.length()||s1.length()==s2.length() && s1<s2)
{
cout<<"-";
swap(s1,s2);
}
f(s1,x);
f(s2,y);
sub(x,y,z);
p(z);
}
这里空空如也
有帮助,赞一个