카테고리 없음
백준 2차원 배열
now0204
2023. 4. 1. 22:04
2738 - 행렬의 덧셈
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String[] rowcol = br.readLine().split(" ");
int row = Integer.valueOf(rowcol[0]);
int col = Integer.valueOf(rowcol[1]);
int[][] arr = new int[row][col];
//행렬 입력
for(int i=0 ;i<2;i++){
for(int j=0 ; j< row; j++){
rowcol = br.readLine().split(" ");
for(int k=0; k< col;k++){
arr[j][k]+=Integer.valueOf(rowcol[k]);
}
}
}
//행렬 출력
for(int[] a: arr){
for(int b : a){
bw.write(b+" ");
}
bw.write("\n");
}
bw.flush();
bw.close();
}