//土尔逊Torson 编写于2023/05/21 #include <iostream> #include <cstdio> #include <string> #include <cstring> using namespace std; const int MAXN = 10000; struct BigInteger082 { //定义大数 int digit[MAXN]; //数字位 int length; //大数大小 BigInteger082(); BigInteger082 operator=(string str); BigInteger082 operator+(const BigInteger082& b); friend istream& operator >> (istream& in, BigInteger082& x); friend ostream& operator << (ostream& out, const BigInteger082& x); }; istream& operator >> (istream& in, BigInteger082& x) {//定义输入操作 string str; in >> str; x = str; //用定义了的赋值操作符( = ) return in; } ostream& operator << (ostream& out, const BigInteger082& x) {//定义输出操作 for (int i = x.length - 1; i >= 0; --i) { out << x.digit[i]; } return out; } BigInteger082::BigInteger082() {//初始化大数 memset(digit, 0, sizeof(digit)); length = 0; } BigInteger082 BigInteger082::operator=(string str) {//定义 赋值 操作符 memset(digit, 0, sizeof(digit)); length = str.size(); for (int i = 0; i < length; ++i) { //逆向存储大数 digit[i] = str[length - i - 1] - '0'; } return *this; } BigInteger082 BigInteger082::operator+(const BigInteger082& b) {//定义 + 操作符 BigInteger082 answer; int carry = 0; for (int i = 0; i < length || i < b.length; ++i) {//两个逆置的大数从低位向高位依次相加 int current = carry + digit[i] + b.digit[i]; //也就是从digit[0] 到 digit[length-1] carry = current / 10; answer.digit[answer.length++] = current % 10; } if (carry != 0) { answer.digit[answer.length++] = carry; } return answer; } int main() { BigInteger082 a; BigInteger082 b; while (cin >> a >> b) { //计算大数 a+b 并输出结果 cout << a + b << endl; } system("pause"); return EXIT_SUCCESS; } // 64 位输出请用 printf("%lld")