Hyunebee
2차원 배열의 합 본문
import java.util.*;
class Main {
public int solution(int[][] arr, int n){
int MAX_Result = 0;
int result_w = 0;
int result_h = 0;
for (int i = 0; i < n; i++){
for (int j =0; j < n; j++){
result_w += arr[i][j]; // 가로방향의 합
result_h += arr[j][i]; // 세로방향의 합
}
MAX_Result = Math.max(result_h,MAX_Result);
MAX_Result = Math.max(result_w,MAX_Result);
result_w = result_h = 0;
}
result_w = 0;
result_h = 0;
for(int i =0; i < n; i++){
result_w += arr[i][i];// 우측 아래 대각선
result_h += arr[i][n-i-1];// 좌측 아래 대각선
}
MAX_Result = Math.max(result_h, MAX_Result);
MAX_Result = Math.max(result_w, MAX_Result);
return MAX_Result;
}
public static void main(String[] args){
Main T = new Main();
Scanner kb = new Scanner(System.in);
int n = kb.nextInt();
int[][] arr=new int[n][n];
for(int i=0; i<n; i++){
for(int j = 0; j < n; j++){
arr[i][j] = kb.nextInt();
}
}
System.out.println(T.solution(arr, n));
}
}