恶魔猎手 • 3个月前
using namespace std; string a, b, d; long long a1[20000], b1[20000], c[20000], k[20000], s = 0, n = 0, m = 0;
void reverse(string d, long long k[]) {
long long n = d.size(), j = 0;
for (int i = n - 1; i >= 0; i--) {
k[j] = d[i] - '0';
j++;
}
}
int main() {
getline(cin, a);
getline(cin, b);
reverse(a, a1);
reverse(b, b1);
m = a.size();
n = b.size();
if ((m > n) || (n == m && a[0] < b[0])) {
cout << '-';
reverse(b, a1);
reverse(a, b1);
} else {
reverse(a, a1);
reverse(b, b1);
}
for (int i = 0; i < 20000; i++) {
c[i] += a1[i] - b1[i];
if (c[i] < 0) {
c[i] += 10;
c[i + 1] -= 1;
}
}
for (int i = 20000 - 1; i >= 0; i--) {
if (c[i] != 0) {
s = i;
break;
}
}
for (int i = s; i >= 0; i--) {
cout << c[i];
}
return 0;
}
评论:
请先登录,才能进行评论