//高精度减法
作者:互联网
#include <bits/stdc++.h>
using
namespace
std;
string sa,sb;
int
na[1005],i,j,nb[1005],nc[1005];
int
lena,lenb,lenc;
int
main()
{
cin>>sa>>sb;
lena=sa.size(); lenb=sb.size(); lenc=max(lena,lenb);
if
(lena<lenb || (lena==lenb && sa<sb)){
swap(sa,sb);
swap(lena,lenb);
cout<<
"-"
;
}
for
(i=1;i<=lena;i++) na[i]=sa[lena-i]-48;
for
(i=1;i<=lenb;i++) nb[i]=sb[lenb-i]-48;
for
(i=1;i<=lenc;i++){
nc[i]=na[i]-nb[i];
if
(nc[i]<0){
na[i+1]--;
nc[i]+=10;
}
}
while
(nc[lenc]==0 && lenc>1) lenc--;
for
(i=lenc;i>=1;i--) cout<<nc[i];
return
0;
}
标签:lenc,lenb,lena,高精度,nc,sb,sa,减法 来源: https://blog.csdn.net/sunxinzehh/article/details/118710794