#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
string str;
while(cin>>str){
string a, b, res;
int k = str.find('-');
a = str.substr(0, k);
b = str.substr(k+1);
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
int c = 0;
for(int i = 0; i < a.size()|| i < b.size(); i++){
int u = i < a.size() ? a[i] - '0': 0;
int v = i < b.size() ? b[i] - '0': 0;
if( u + c < v){
res += to_string(u + c + 10 - v);
c = -1;
}else{
res += to_string(u + c - v);
c = 0;
}
}
k = res.size() - 1;
while(k > 0 && res[k]=='0') k--;
res = res.substr(0, k+1);
reverse(res.begin(), res.end());
cout<<res<<endl;
}
return 0;
}
大数相减
最新推荐文章于 2021-03-27 06:56:52 发布