#C08L01P03. C08.L01.高精度加法与减法.填空题2.高精度减法
C08.L01.高精度加法与减法.填空题2.高精度减法
题目描述
高精度减法模板
输入格式
两行,一行一个整数。
输出格式
一行,一个整数。
样例
2468
123
2345
程序填空
#include<bits/stdc++.h>
using namespace std;
string ans;
int main()
{
string a,b;
cin>>a>>b;
if(a.size()<b.size()||(a.size()==b.size()&&a<b))
{
swap(a,b);
printf("填空(1)");
}
int i,j,t,ov=0,len_a,len_b,p=0;
len_a = a.size();
len_b = b.size();
char c;
for(i=len_a-1,j=len_b-1;i>=0||j>=0;i--,j--)
{
t = a[i]-'0'-ov;
if(j>=0)
t -= b[j] -'0';
if(t<0)
{
t += 填空(2);
ov = 1; //借位
}
else
填空(3); //没有借位
c = '0' + t;
ans = 填空(4) ;
}
while(ans.size()>1&&填空(5)) ans.erase(0,1);
cout<<ans;
return 0;
}
填空(1): {{ input(1) }}
填空(2): {{ input(2) }}
填空(3): {{ input(3) }}
填空(4): {{ input(4) }}
填空(5): {{ input(5) }}
相关
在以下作业中: