본문 바로가기
알고리즘/SWExpert

SWExpert_2805_농작물 수확하기

by 박 현 황 2021. 2. 3.

문제 링크

 

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV7GLXqKAWYDFAXB&categoryId=AV7GLXqKAWYDFAXB&categoryType=CODE&problemTitle=%EB%86%8D%EC%9E%91%EB%AC%BC&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=&pageSize=10&pageIndex=1

 

SW Expert Academy

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

swexpertacademy.com

 

 

 

import java.util.Arrays;
import java.util.Scanner;
 
public class Solution{
 
    private static int T;
    private static int N;
    private static int field[][];
    private static int field2[][];
    private static int sum=0;
    private static int num=0,num2=0;
     
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
         
        T = sc.nextInt();
         
        for(int t=1;t<=T;t++) {
            N = sc.nextInt();
            field = new int[N][N];
            field2 = new int[N][N];
            num = 0;
            num2 = N-1;
            sum = 0;
             
            for(int i=N/2;i>0;i--) {
                //if N ==5  i== 2
                for(int j=i;j<(N-i);j++) {
                    field2[num][j] = 1;
                }   
                num++;
            }
             
            for(int i=0;i<N;i++)
                field2[N/2][i] = 1;
             
            for(int i=N/2;i>=0;i--) {
                for(int j = N-(i+1);j>=i;j--) {
                    field2[i+(N/2)][j] = 1;
                }
            }
             
             
            for(int i=0;i<N;i++) {
                String str = sc.next();
                for(int j=0;j<N;j++) {
                    field[i][j] = str.charAt(j)-'0';
                }
            }
 
 
            for(int i=0;i<N;i++) {
                for(int j=0;j<N;j++) {
                    if(field2[i][j] == 1) {
                        sum += field[i][j];
                    }
                }
            }
             
            System.out.println("#"+t+" "+sum);
        }
    }
}

 

별찍기랑 비슷해서 별 찍기로 먼저 확인한 후에 별 찍기 for문 가져와서 더할려고 했는데

자꾸 어디서 안되서 짜증나서 그냥 별찍기 처럼 1로 배열 채운 후에 

field[i][j] == 1 이런 식으로 풀었다.

난중에 기운 생기면 그냥 for문 써서 다시 풀어볼란다...

'알고리즘 > SWExpert' 카테고리의 다른 글

SWExpert_1225_암호생성기  (1) 2021.02.04
SWExpert_2001_파리퇴치  (0) 2021.02.03
SWExpert_1873_상호의 배틀필드  (0) 2021.02.03
SWExpert_1289_원재의 메모리 복구하기  (0) 2021.02.03
SWExpert_1208_Flatter  (0) 2021.02.02