import java.util.Scanner;
public class Main {
public static int isMax(int[] a,int[] b){
int t=1;
for(int i=100;i>=0;i--){
if(a[i]>b[i]){
t=1;
break;
}else if(a[i]<b[i]){
t=-1;
break;
}
}
return t;
}
public static void main(String[] args)
{
Scanner cin=new Scanner(System.in);
int[] a=new int[101];
int[] b=new int[101];
int[] result=new int[101];
for (int i = 0; i <101; i++)
{
a[i]=b[i]=result[i]=0;
}
String line1=cin.nextLine();
String line2=cin.nextLine();
for (int i = 0; i < line1.length(); i++)
a[i]=(int)line1.charAt(line1.length()-1-i)-48;
for (int i = 0; i < line2.length(); i++)
b[i]=(int)line2.charAt(line2.length()-1-i)-48;
int r=0;
if(isMax(a,b)==1){
for (int i = 0; i < 101; i++)
{
if(a[i]>=b[i]){
result[i]=a[i]-b[i]-r;
result[i]%=10;
r=a[i]/10;
}else if(a[i]<b[i]){
a[i]+=10;
result[i]=a[i]-b[i]-r;
result[i]%=10;
r=a[i]/10;
}
}
}else if(isMax(a,b)==-1){
for (int i = 0; i < 101; i++)
{
if(b[i]>=a[i]){
result[i]=b[i]-a[i]-r;
result[i]%=10;
r=b[i]/10;
}else{
b[i]+=10;
result[i]=b[i]-a[i]-r;
result[i]%=10;
r=b[i]/10;
}
}
}
int flag=100;
for (int i = 100; i>-1; i--) {
if (result[i]!=0&&result[i]!=-1) {
flag=i;
break;
}
}
for (int i = flag; i >-1; i--) {
System.out.print(result[i]);
}System.out.println();
}
}
高精度减法 蓝桥杯
最新推荐文章于 2022-03-28 21:31:51 发布