提交时间:2023-10-06 11:04:18
运行 ID: 105375
#include<bits/stdc++.h> using namespace std; int main(){ int a[50001],b[50001],c[50001],lena,lenb,lenc; char n[50001],n1[50001],n2[50001]; gets(n1); gets(n2); if(strlen(n1)<strlen(n2)||(strlen(n1)==strlen(n2)&&strcmp(n1,n2)<0)){ strcpy(n,n1); strcpy(n1,n2); strcpy(n2,n); } lena=strlen(n1);lenb=strlen(n2); for(int i=0;i<lena;i++) a[lena-i]=int(n1[i]-'0'); for(int i=0;i<lenb;i++) b[lenb-i]=int(n2[i]-'0'); int i=1; while(i<=lena||i<=lenb){ if(a[i]<b[i]){ a[i]+=10; a[i+1]--; } c[i]=a[i]-b[i]; i++; } lenc=i; while((c[lenc]==0)&&(lenc>1)) lenc--; for(i=lenc;i>=1;i--) cout<<c[i]; cout<<endl; return 0; }