-
[SWEA] #2805 _ 농작물 수확하기Problem Solving/SWEA 2019. 8. 4. 10:06
[농작물 수확하기] https://swexpertacademy.com/main/code/problem/problemDetail.do
규칙을 찾아 마름모 내의 값을 더하여 출력하는 간단한 문제이다.
[ 소스 코드 ]
#include <cstdio> #include <algorithm> #define MAX_N 49 int n, farm[MAX_N + 1][MAX_N + 1] = { 0, }; int calc_gain(); int main() { int test_case; scanf("%d", &test_case); for (int i = 1; i <= test_case; i++) { scanf("%d", &n); for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { scanf("%1d", &farm[j][k]); } } printf("#%d %d\n", i, calc_gain()); } return 0; } int calc_gain() { int pivot = n / 2, result = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i <= pivot) { if (j >= pivot - i && j <= pivot + i) result += farm[i][j]; } else { if (j >= i - pivot && j < n - (i - pivot)) result += farm[i][j]; } } } return result; }
'Problem Solving > SWEA' 카테고리의 다른 글
[SWEA] #5644 _ 무선 충전 (0) 2019.08.04 [SWEA] #5215 _ 햄버거 다이어트 (0) 2019.08.04 [SWEA] #1215 _ 회문1 (0) 2019.08.04 [SWEA] #5658 _ 보물상자 비밀번호 (0) 2019.07.17 [SWEA] #1249 _ 보급로 (0) 2019.07.17 댓글