SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.util.Scanner;
import java.io.FileInputStream;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int test_case = 1; test_case <= T; test_case++)
{
int N = sc.nextInt();
int M = sc.nextInt();
int [][] array;
array = new int[N][N];
for (int i =0; i<N; i++){
for(int j=0; j<N; j++){
array[i][j] = sc.nextInt(); // N 크기의 map 생성
}
}
int max = 0;
for (int k = 0; k<N-M+1; k++){
for (int l = 0; l<N-M+1; l++){
int score=0;
for(int m=0; m<M; m++){
for(int n=0; n<M; n++){
score+=array[k+m][l+n];
}
}
if(max<score)
max = score;
}
}
System.out.println("#" + test_case + " " + max);
}
}
}
2중 for문으로 2차원 배열에 i랑 j 받아서 그대로 입력,
4중 for문으로 한칸씩 늘려가면서 M 범위에 맞게 하나씩 두드려보고 최댓값 찾기
'SWEA' 카테고리의 다른 글
[SWEA] 지그재그 숫자 (1) | 2024.09.26 |
---|---|
[SWEA] 초심자의 회문 검사 (0) | 2024.09.25 |
[SWEA] 파스칼의 삼각형 (1) | 2024.09.24 |
[SWEA] 패턴 마디의 길이 (0) | 2024.09.21 |
[SWEA] 간단한 369게임 (0) | 2024.09.20 |