작성
·
186
0
public class Main {
public int solution(int n , int [][] arr){
int answer = Integer.MIN_VALUE;
int sum1 = 0;
int sum2 = 0;
int sum3 = 0;
int sum4 = 0;
for(int i=0, k = 4; i < n ; i++ , k--){
sum3+=arr[i][i]; //대각선들의 합
sum4+=arr[k][k];
for(int j=0; j < n ; j++){
sum1 += arr[i][j]; //행의 합
sum2 += arr[j][i]; //열의 합
}
answer=Math.max(answer, sum1);
answer=Math.max(answer, sum2);
sum1 = 0;
sum2 = 0;
}
answer=Math.max(answer, sum3);
answer=Math.max(answer, sum4);
return answer;
}
public static void main(String[] args) {
Main t = new Main();
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int [][] arr = new int[n][n];
for(int i=0; i < arr.length ; i++){
for(int j=0; j <arr[i].length; j++){
arr[i][j] = scan.nextInt();
}
}
System.out.println(t.solution(n,arr));
}
}