#include <iostream>
using namespace std;

class M {
private:
    int data[2][3];

public:
    // 重载输入运算符 >>
    friend istream& operator>>(istream& in, M& m) {
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 3; j++) {
                in >> m.data[i][j];
            }
        }
        return in;
    }

    // 重载输出运算符 <<
    friend ostream& operator<<(ostream& out, const M& m) {
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 3; j++) {
                out << m.data[i][j];
                if (j != 2) out << " ";
            }
            if (i != 1) out << endl;
        }
        return out;
    }

    // 重载加法运算符 +
    M operator+(const M& other) const {
        M result;
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 3; j++) {
                result.data[i][j] = this->data[i][j] + other.data[i][j];
            }
        }
        return result;
    }
};

int main() {
    M a, b, c;
    cin >> a;
    cin >> b;
    c = a + b;
    cout << c << endl;
    return 0;
}

标签: none

添加新评论