코딩테스트/SWEA

[SWEA] 2805. 농작물 수확하기

ankisile 2023. 5. 15. 00:06

문제

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV7GLXqKAWYDFAXB 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

코드

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);
		}
		
	}

}