https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV7GLXqKAWYDFAXB
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
for (int t = 1; t <= T; t++) {
int N = Integer.parseInt(br.readLine()); // 농장의 크기
char[][] farm = new char[N][N];
for(int n = 0; n < N; n++) {
String string = br.readLine();
farm[n] = string.toCharArray();
}
int count = 0;
for(int i = 0; i <= N/2; i++) {
for(int j = N/2-i; j <= N/2+i; j++) {
if(i == N/2) // 가운데 row일 경우
count += Integer.parseInt(farm[i][j] + "");
else {
count += Integer.parseInt(farm[i][j] + ""); // 맨 위 row부터 가운데 row 직전까지
count += Integer.parseInt(farm[N-i-1][j] + ""); // 맨 아래 row부터 가운데 row 직전까지
}
}
}
System.out.println("#" + t + " " + count);
}
}
}