행렬을 2차원 배열로 만들어 더하는 문제
#include <iostream>
#include <vector>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, M;
cin >> N >> M;
vector<vector<int>> ans;
for (int i = 0; i < N; i++) {
vector<int> a;
int input;
for (int j = 0; j < M; j++) {
cin >> input;
a.push_back(input);
}
ans.push_back(a);
}
for (int i = 0; i < N; i++) {
int input;
for (int j = 0; j < M; j++) {
cin >> input;
ans[i][j] += input;
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cout << ans[i][j] << " ";
}
cout << "\n";
}
return 0;
}