Deep_Lee
article thumbnail

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

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

 


 

์•„์ง ๊ทธ๋ฆผ๋ฌธ์ œ์— ์ต์ˆ™ํ•˜์ง€ ์•Š์€๋ฐ, 

๊ณ ๋ฏผํ•˜๋‹ค๊ฐ€ ๋งˆ๋ฆ„๋ชจ๋ฅผ ๋‚˜๋ˆ ์„œ ๊ตฌํ•˜๋ฉด ๋œ๋‹ค.

 

๊ฐ€์šด๋ฐ ๊ฐ€๋กœ์ค„์„ ํฌํ•จํ•˜์—ฌ ์ƒ๋‹จ, ๊ทธ๋ฆฌ๊ณ  ํ•˜๋‹จ์˜ ์‚ผ๊ฐํ˜• ๋ถ€๋ถ„.

 

 

import java.util.Scanner;
class Solution{
    public static void main(String args[]) throws Exception{
        
         Scanner kb = new Scanner(System.in);
        int t = kb.nextInt();
        for (int test_case = 1; test_case <= t; test_case++) {
            int n=kb.nextInt();
            int[][] arr=new int[n][n];
            for(int i=0; i<n; i++){
                String str=kb.next();
                for(int j=0; j<n; j++){
                    arr[i][j]=str.charAt(j)-'0';
                }
            }
            int sum=0;
            // ์ค‘๊ฐ„๋ถ€ ~ ์ƒ๋‹จ 
            for(int i=0; i<=n/2; i++){
                for(int j=n/2-i; j<=n/2+i; j++){
                    sum+=arr[i][j];
                }
            }
            // ์ค‘๊ฐ„๋ถ€์ œ์™ธ ~ ํ•˜๋‹จ ์‚ผ๊ฐํ˜•
            int a=1; // a๋Š” ํ–‰์˜ ์‹œ์ž‘์  ( ์ ์  ++ )
            for(int i=n/2+1; i<n; i++){
                for(int j=a; j<=n-1-a; j++){ // j๋Š” ํ–‰์˜ ๋์  ( ์ ์  -- )
                    sum+=arr[i][j];
                }
                a++;
            }
            System.out.println("#" + test_case +" "+sum);
        }
    }
}