1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| #include<bits/stdc++.h> using namespace std; int a[100000]={0},b[100000]={0},c[100000]={0}; int i,j,k,l,m,n,flag; string a1,b1,c1; void did(){ int i=0; while(i<=a[0]){ i++; if(a[i]<b[i]){ a[i+1]--; a[i]+=10; } c[i]=a[i]-b[i]; c[0]++; } } int main(){ cin>>a1>>b1; a[0]=a1.length(); b[0]=b1.length(); if(a[0]<b[0] || (a[0]==b[0] && a1<b1)){ c1=b1;b1=a1;a1=c1; swap(a[0],b[0]); cout<<"-"; } for(i=1;i<=a[0];i++) { a[i]=a1[a[0]-i]-'0'; } for(i=1;i<=b[0];i++){ b[i]=b1[b[0]-i]-'0'; } did(); while(c[c[0]]==0&&c[0]>1) c[0]--; for(i=c[0];i>=1;i--) { cout<<c[i]; } return 0; }
|