1 条题解

  • 0
    @ 2026-10-7 23:01:14

    【本题解由站长编写】

    读入 N、M 和两个矩阵,对应位置相加输出。每行数字间用空格隔开、行末不留空格,避免 Presentation Error。

    代码(C++17)

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        int n, m;
        cin >> n >> m;
        vector<vector<long long>> a(n, vector<long long>(m)), b(n, vector<long long>(m));
        for (auto &r : a) for (auto &x : r) cin >> x;
        for (auto &r : b) for (auto &x : r) cin >> x;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                cout << a[i][j] + b[i][j] << (j + 1 == m ? '\n' : ' ');
        return 0;
    }
    
    • 1

    信息

    ID
    4303
    时间
    1000ms
    内存
    512MiB
    难度
    5
    标签
    递交数
    0
    已通过
    0
    上传者