728x90
반응형
풀이 :
4중 for문 -> map[i][j] ~ map[i+x][j+y]
Code
public class Solution2001 {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int tc = 1; tc <= T; tc++) {
int N = sc.nextInt(); // 5
int M = sc.nextInt(); // 2
int[][] map = new int[N][N];
int maxSum = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
map[i][j] = sc.nextInt();
}
}
for (int i = 0; i <= N - M; i++) {
for (int j = 0; j <= N - M; j++) {
int sum = 0;
for (int x = 0; x < M; x++) {
for (int y = 0; y < M; y++) {
sum += map[i + x][j + y];
}
}
maxSum = Math.max(sum, maxSum);
}
}
System.out.printf("#%d %d\n", tc, maxSum);
}
sc.close();
}
}
728x90
반응형
'SWEA' 카테고리의 다른 글
swea 2007 [D2] 패턴 마디의 길이 JAVA (1) | 2023.11.22 |
---|---|
swea 2005 [D2] 파스칼의 삼각형 JAVA (0) | 2023.11.22 |
swea 1989 [D2] 초심자의 회문 검사 JAVA (0) | 2023.11.22 |
swea 1986 [D2] 지그재그 숫자 JAVA (0) | 2023.11.22 |
swea 1984 [D2] 중간 평균값 구하기 JAVA (2) | 2023.11.22 |