View Code of Problem 51

#include <iostream>
#include "vector"

using namespace std;

int main() {

    int n;
    cin >> n;

    //接收
    vector<vector<int>> matrix(n);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            int temp;
            cin >> temp;
            matrix[i].push_back(temp);
        }
    }

    //求和
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < i+1; ++j) {
            sum+=matrix[i][j];
        }
    }

    cout<<sum;
    return 0;
}

Double click to view unformatted code.


Back to problem 51