rt,悬一关,代码:
#include <bits/stdc++.h>
namespace Integer {
const std::string symbol = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
template <class T = int, int binary = 10> class BigInt {
private:
T n;
std::vector<T> a;
bool f;
public:
BigInt() { Init(); }
T &operator[](int i) { return a[i]; }
void Init() {
n = f = 1;
a.clear();
}
friend std::istream &operator>>(std::istream &is, BigInt &a) {
std::string s;
is >> s;
a.n = s.size();
if (s[0] == '-') {
a.f = 0;
a.n--, s.erase(0, 1);
}
for (int i = 0; i < a.n; i++) {
a.a.push_back((s[a.n - i - 1] >= 'A' && s[a.n - i - 1] <= 'Z'
? s[a.n - i - 1] - 'A' + 10
: s[a.n - i - 1] - '0'));
}
return is;
}
friend std::ostream &operator<<(std::ostream &os, BigInt a) {
for (; a.n > 1 && !a[a.n - 1]; a.n--) {
}
if (!a.f) {
os << '-';
}
for (int i = a.n - 1; i >= 0; i--) {
os << symbol[a[i]];
}
return os;
}
bool operator<(BigInt x) {
if (n == x.n) {
for (int i = n - 1; i >= 0; i--) {
if (a[i] != x[i]) {
return a[i] < x[i];
}
}
}
return n < x.n;
}
BigInt operator-(BigInt x) {
BigInt y, z = *this;
if (z < x) {
y.f = 0, std::swap(z, x);
}
y.n = z.n;
y.a.resize(y.n);
for (int i = 0; i < y.n; i++) {
if (i >= std::min(z.n, x.n)) {
y[i] = z[i];
continue;
}
y[i] = z[i] - x[i];
}
for (int i = 0; i < y.n - 1; i++) {
if (y[i] < 0) {
y[i + 1]--;
y[i] += binary;
}
}
for (; !y[y.n - 1] && y.n > 1; y.n--) {
}
return y;
}
};
}; // namespace Integer
using namespace std;
using namespace Integer;
int main() {
#ifndef ONLINE_JUDGE
freopen("P2142_3.in", "r", stdin);
freopen("P2142.out", "w", stdout);
#endif
BigInt<> a, b;
cin >> a >> b;
cout << a - b;
return 0;
}