You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
796 B
36 lines
796 B
2 years ago
|
#include <bits/stdc++.h>
|
||
|
using namespace std;
|
||
|
|
||
|
const int N = 1e5 + 10;
|
||
|
int a[N], al;
|
||
|
int b[N], bl;
|
||
|
|
||
|
void sub(int a[], int &al, int b[], int &bl) {
|
||
|
int t = 0;
|
||
|
al = max(al, bl);
|
||
|
for (int i = 0; i < al; i++) {
|
||
|
t = a[i] - b[i] - t;
|
||
|
a[i] = (t + 10) % 10;
|
||
|
t < 0 ? t = 1 : t = 0;
|
||
|
}
|
||
|
while (al > 0 && a[al] == 0) al--;
|
||
|
}
|
||
|
|
||
|
int main() {
|
||
|
string x, y;
|
||
|
cin >> x >> y;
|
||
|
|
||
|
// 负号
|
||
|
if (x.size() < y.size() || (x.size() == y.size() && x < y)) {
|
||
|
printf("-");
|
||
|
swap(x, y);
|
||
|
}
|
||
|
|
||
|
for (int i = x.size() - 1; i >= 0; i--) a[al++] = x[i] - '0';
|
||
|
for (int i = y.size() - 1; i >= 0; i--) b[bl++] = y[i] - '0';
|
||
|
|
||
|
sub(a, al, b, bl);
|
||
|
|
||
|
for (int i = al; i >= 0; i--) printf("%d", a[i]);
|
||
|
return 0;
|
||
|
}
|