SWEA - 2805 : 농작물 수확하기 [자바]

HungAh.log·2021년 8월 12일
0
import java.io.*;
import java.util.*;

class Solution {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int T = Integer.parseInt(br.readLine()); // 테스트 케이스 수

		for (int test_case = 1; test_case <= T; test_case++) {
			int N = Integer.parseInt(br.readLine());
			int[][] crops = new int[N][N];

			for (int i = 0; i < crops.length; i++) {
				char[] c = br.readLine().toCharArray();
				for (int j = 0; j < crops.length; j++) {
					crops[i][j] = c[j] - '0';
				}
			}

			// .substring(n,m);

			int sum = 0;
			int fix = (N + 1) / 2 - 1;
			for (int i = 0; i < (crops.length + 1) / 2; i++) {
				for (int j = 0; j < crops.length - i * 2; j++) {
					if (i == 0) {
						sum += crops[fix][j];
					} else {
						sum += crops[fix - i][i + j];
						sum += crops[fix + i][i + j];
					}
				}
			}
			sb.append("#").append(test_case).append(" ").append(sum).append("\n");
		}
		System.out.println(sb);
		br.close();
	}
}
profile
👩🏻‍💻

0개의 댓글

관련 채용 정보