반응형
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Solution_2001_파리퇴치 {
static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
static StringBuilder output = new StringBuilder();
static StringTokenizer tokens;
static int N, M ,T;
static int [][] map;
public static void main(String[] args) throws NumberFormatException, IOException {
T = Integer.parseInt(input.readLine());
for (int t = 1; t <= T; t++) {
int answer = 0;
tokens = new StringTokenizer(input.readLine());
N = Integer.parseInt(tokens.nextToken());
M = Integer.parseInt(tokens.nextToken());
map = new int[N][N];
for (int i = 0; i < N; i++) {
tokens = new StringTokenizer(input.readLine());
for (int j = 0; j < N; j++) {
map[i][j] = Integer.parseInt(tokens.nextToken());
}
}
//입력확인
// for (int[] row : map) {
// System.out.println(Arrays.toString(row));
// }
for(int r=0; r<N-M+1; r++) {
for (int c = 0; c < N-M+1; c++) {
answer = Math.max(answer, cal(r,c));
}
}
/////
output.append("#").append(t).append(" ").append(answer).append("\n");
}
System.out.println(output);
}
static int cal(int r, int c) {
int sum = 0;
for (int i = r; i < M+r; i++) {
for (int j = c; j < M+c; j++) {
sum += map[i][j];
}
}
return sum;
}
}
반응형
'코딩테스트 > 삼성 SW Expert 문제' 카테고리의 다른 글
[Java] SWEA_1228_암호문1 (0) | 2021.02.08 |
---|---|
[Java] SWEA_1225_암호생성기 (0) | 2021.02.08 |
[Java] SWEA_1208_Flatten (0) | 2021.02.08 |
[Java] SWEA_1954_달팽이숫자 (0) | 2021.02.08 |
[Java] SWEA_1940_가랏RC카 (0) | 2021.02.08 |