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);
}
}
}
'Algorithm > 백준+프로그래머스+SWEA+정올+구름' 카테고리의 다른 글
[Algorithm] 백준 12927 배수 스위치 (0) | 2021.08.27 |
---|---|
[Algorithm] SWEA 7236 저수지의 물의 총 깊이 구하기 (0) | 2021.08.26 |
[Algorithm] 백준 2999 비밀 이메일 (0) | 2021.08.25 |
[Algorithm] 백준 2941 크로아티아 알파벳 (0) | 2021.08.25 |
[Algorithm] 백준 13300 방 배정 (0) | 2021.08.24 |