문제
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV7GLXqKAWYDFAXB
코드
import java.io.*;
class Solution {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
for(int test_case = 1; test_case <= T; test_case++)
{
int n = Integer.parseInt(br.readLine());
int board[][] = new int[n][n];
for(int i=0;i<n;i++) {
String str = br.readLine();
for(int j=0;j<n;j++) {
board[i][j] = str.charAt(j)-'0';
}
}
int result = 0;
for(int i=0;i<n;i++) {
int start = n/2-i;
int end = n/2+i+1;
if(i > n/2) {
start = n/2 - (n-i-1);
end = n/2 + (n-i);
}
for(int j = start; j < end;j++) {
result += board[i][j];
}
}
System.out.println("#"+test_case+" "+result);
}
}
}