https://www.acmicpc.net/problem/2738
소스 코드 (c++)
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m;
int arr[101][101];
int result_arr[101][101] = {{0,},};
cin >> n >> m;
for (int i = 0; i < 2; i++) {
for (int y = 0; y < n; y++) {
for (int x = 0; x < m; x++)
{
cin >> arr[y][x];
result_arr[y][x] += arr[y][x];
}
}
}
for (int y = 0; y < n; y++) {
for (int x = 0; x < m; x++)
{
cout << result_arr[y][x] << " ";
}
cout << endl;
}
}
알게된 점
// 1. 2차원 배열 초기화
int arr[3][3] = {0};
// 2. 2차원 배열 초기화
int arr[3][3] = {{0,}, };
// 3. 2차원 배열 초기화 - #include <cstring>
int arr[3][3];
memset(arr, 0, sizeof(arr));
알고는 있는 내용이나 약간 아리까리 했던 지점이 있었는데 다시한번 확인하게 되었다.
'알고리즘 > BaekJoon 단계별로 풀어보기' 카테고리의 다른 글
[일반수학1] 11005번 - 진법 변환 2 (0) | 2024.11.05 |
---|---|
[일반 수학1] 2745번 - 진법 변환 (0) | 2024.11.04 |
[2차원 배열] 2563번 - 색종이 (c++) (0) | 2024.11.03 |
[2차원 배열] 10798번 - 세로 읽기(c++) (0) | 2024.11.03 |
[2차원 배열] 2566번 - 최댓값 (c++) (0) | 2024.11.03 |