string字符实现
#include <iostream>
using namespace std;
string a, b, rev_a, rev_b;
string rev(string a){
string res;
for(char c:a) res = c + res;
return res;
}
// a >= b,返回true
bool ge(string a, string b){
if(a.size() != b.size()) return a.size() > b.size();
int len = a.size();
for(int i = 0; i < len; i++){
if(a[i] - '0' > b[i] - '0') return true;
else if(a[i] - '0' < b[i] - '0') return false;
}
return true;
}
string remove_pre0(string a){
int i = a.size() - 1;
while(a.size() >= 1){
if(a[i] == '0') a = a.substr(0, a.size()-1), i = a.size() - 1;
else break;
}
if(a == "") return "0";
return a;
}
string sub(){
string res;
int neg = 0;
if(!ge(a, b) && a != b) swap(rev_a, rev_b), neg = 1; // a < b,返回结果加上负号
int len = rev_b.size();
int borrow = 0;
int i = 0;
for(; i < len; i++){
int x = rev_a[i] - '0', y = rev_b[i] - '0';
if(borrow) x -= borrow, borrow = 0;
if(x < y){
borrow++;
x += 10;
}
res += to_string(x - y);
}
int len_a = rev_a.size();
while(i < len_a){
int x = rev_a[i] - '0';
if(borrow) x -= borrow, borrow = 0;
if(x < 0){
borrow++;
x += 10;
}
res += to_string(x);
i++;
}
res = remove_pre0(res);
if(neg) res += "-";
return res;
}
int main(){
cin >> a >> b;
rev_a = rev(a);
rev_b = rev(b);
cout << rev(sub());
}