#include <bits/stdc++.h>
using namespace std;
struct big_number {
bool is_postive;
string s;
big_number () {}
big_number (string ss) { if (ss[0] != '-') {this->s = ss; this->is_postive = true;} else {this->s = ss.substr(1, ss.size()); this->is_postive = false;}}
big_number (string ss, bool flag) {this->s = ss; this->is_postive = flag; }
void print() {if (is_postive == false) cout << "-"; cout << s;}
void println() {if (is_postive == false) cout << "-"; cout << s << "\n";}
int size() { return int(s.size()); }
bool operator < (const big_number &b) const {
if (int(s.size()) != int(b.s.size())) return int(s.size()) < int(b.s.size());
return s < b.s;
}
bool operator > (const big_number &b) const {
if (int(s.size()) != int(b.s.size())) return int(s.size()) > int(b.s.size());
return s > b.s;
}
bool operator == (const big_number &b) const {
return s == b.s;
}
bool operator != (const big_number &b) const {
return s != b.s;
}
friend inline big_number operator + (const big_number &p, const big_number &q) {
if (p.is_postive != q.is_postive) {
if (p.is_postive == false) {big_number np(p.s, true), nq(q.s, true); return nq - np;}
else {big_number np(p.s, true), nq(q.s, true); return np - nq;}
}
string a = p.s, b = q.s;
reverse(a.begin(), a.end()); reverse(b.begin(), b.end());
if (int(a.size()) < int(b.size())) swap(a, b);
int t = 0; big_number ans;
for (int i = 0; i < int(a.size()); i ++ ) {
if (i < int(a.size())) t += (a[i] - '0');
if (i < int(b.size())) t += (b[i] - '0');
ans.s += char('0' + (t % 10)); t /= 10;
}
if (t) ans.s += char('0' + (t % 10));
reverse(ans.s.begin(), ans.s.end());
if (p.is_postive == false and q.is_postive == false) ans.is_postive = false;
else ans.is_postive = true;
return ans;
}
friend inline big_number operator - (const big_number &p, const big_number &q) {
if (p.is_postive != q.is_postive) {
if (p.is_postive == false) {big_number np(p.s, false), nq(q.s, false); return nq + np;}
else {big_number np(p.s, true), nq(q.s, true); return np + nq;}
} else {
if (p.is_postive == false) {big_number np(p.s, true), nq(q.s, true); return nq - np;}
}
string a = p.s, b = q.s;
if (a == b) return big_number("0");
reverse(a.begin(), a.end()); reverse(b.begin(), b.end());
int t = 0; big_number ans;
if (p < q) {swap(a, b); ans.is_postive = false; }
for (int i = 0; i < int(a.size()); i ++ ) {
if (i < int(a.size())) t += (a[i] - '0');
if (i < int(b.size())) t -= (b[i] - '0');
ans.s += char('0' + ((t + 10) % 10));
t = t < 0 ? -1 : 0;
}
assert(t == 0);
while (not ans.s.empty() and ans.s.back() == '0') ans.s.pop_back();
reverse(ans.s.begin(), ans.s.end());
return ans;
}
string MUL (string a, int b, int cnt) const {
string B = a, ans; int n = B.size();
int t = 0; reverse(B.begin(), B.end());
if (cnt) ans += string(cnt, '0');
for (int i = 0; i < n; i ++ ) {
t += b * int(B[i] - '0');
ans += char('0' + (t % 10));
t /= 10;
}
while (t) {ans += char('0' + (t % 10)); t /= 10; }
reverse(ans.begin(), ans.end());
return ans;
}
friend inline big_number operator * (const big_number &p, const big_number &q) {
string a = p.s, b = q.s;
if (int(a.size()) < int(b.size())) swap(a, b);
big_number ans("0"), mul(a);
reverse(b.begin(), b.end());
for (int i = 0; i < int(b.size()); i ++ ) {
string now = p.MUL(a, int(b[i] - '0'), i);
ans = ans + big_number(now);
}
if (p.is_postive != q.is_postive) ans.is_postive = false;
else ans.is_postive = true;
return ans;
}
};
int main() {
string x, y; cin >> x >> y;
big_number a(x), b(y), ans;
ans = a + b; ans.println();
ans = a - b; ans.println();
ans = a * b; ans.println();
ans = b - a; ans.println();
ans = (b - a) * (a - b); ans.println();
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现