입력예시
5
3 -5 12 3 -21
-2 11 2 -7 -11
21 -21 -35 -93 -11
9 14 39 -98 -1
-2 -2 -2 -2 -2
출력예시
2 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | import java.io.IOException; import java.util.Scanner; public class Main { public static void main(String[] arg) throws IOException { int i, j, N; int[][] a; Scanner sc = new Scanner(System.in); // 입력 받는 부분 N = sc.nextInt(); a = new int[N][N]; for (i = 0; i < N; i++) { for (j = 0; j < N; j++) a[i][j] = sc.nextInt(); } // 여기서부터 작성 int[] row_sum = new int[N]; int[] col_sum = new int[N]; for(i = 0; i < N; i++){ int row_sum_temp = 0; int col_sum_temp = 0; for (j = 0; j < N; j++){ row_sum_temp += a[i][j]; col_sum_temp += a[j][i]; } row_sum[i] = row_sum_temp; col_sum[i] = col_sum_temp; } int max_row_index = 1; int max_col_index = 1; int row_max = row_sum[0]; int col_max = col_sum[0]; for(i = 1; i < N; i++){ if(row_max < row_sum[i]){ max_row_index = i + 1; row_max = row_sum[i]; } } for(i = 1; i < N; i++){ if(col_max < col_sum[i]){ max_col_index = i + 1; col_max = col_sum[i]; // System.out.println("max_col_index : "+max_col_index); // System.out.println("col_max : "+col_max); } } // 출력 하는 부분 System.out.print(max_row_index + " " + max_col_index); sc.close(); } } |
No comments:
Post a Comment