高精度通用套路
1.字符串输入
2.字符串转数组
3.核心运算
4.前导消0
5.逆序输出
#include<bits/stdc++.h>
using namespace std;
const int N =100005;
int a[N],b[N],c[N];
string x,y;
int main(){
cin>>x>>y;
//字符串输入
int lx=x.length();
int ly=y.length();
//判断结果是否为负
//只有在两个字符串长度相等时,比较才有意义
if(lx<ly || lx==ly && x<y){
swap(x,y);
swap(lx,ly);
cout<<"-";
}
//字符串转数组
for(int i=0;i<lx;i++)
a[lx-i]=x[i]-'0';
for(int i=0;i<ly;i++)
b[ly-i]=y[i]-'0';
//计算
for(int i=1;i<=lx;i++){
if(a[i]<b[i]){
a[i]+=10;
a[i+1]--;
}
c[i]=a[i]-b[i];
}
//前导消0
while(c[lx]==0 &&lx>1){
lx--;
}
//逆序输出
for(int i=lx;i>=1;i--)
printf("%d",c[i]);
}