๐ŸŽฏ Coding Test

[SWEA] 1206. [S/W ๋ฌธ์ œํ•ด๊ฒฐ ๊ธฐ๋ณธ] 1์ผ์ฐจ - View

์—ฐ_์šฐ๋ฆฌ 2022. 2. 10. 16:51
๋ฐ˜์‘ํ˜•
 

SW Expert Academy

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

swexpertacademy.com

 

 

 

๋ฌธ์ œํ’€์ด

import java.util.*;
import java.io.FileInputStream;

class Solution
{
    public static void main(String args[]) throws Exception
    {
     
        Scanner sc = new Scanner(System.in);
        int widthMax = 1000;
        int heightMax = 255;
        int test_count = 10;
 
        for(int test_case = 1; test_case <= test_count; test_case++)
        {
            int buildingCount = sc.nextInt();
 
            int[][] map = new int[widthMax][heightMax];
 
            // ๋นŒ๋”ฉ ์ •๋ณด ์ž…๋ ฅ
            for(int width=0; width<buildingCount; width++){
                int heightLimit = sc.nextInt();
                for(int height=0; height<heightLimit; height++){
                    map[width][height] = 1;
                }
            }
 
            //1๋ฒˆ์งธ ๋นŒ๋”ฉ 1์ธต๋ถ€ํ„ฐ ์™ผ์ชฝ ์˜ค๋ฅธ์ชฝ ํ™•์ธ
            int count = 0;
            for(int width=(0+2); width<(widthMax-2); width++){   //๋งจ ์™ผ์ชฝ ์˜ค๋ฅธ์ชฝ ๋‘์นธ์€ ๊ฑด๋ฌผ ์ง€์–ด์ง€์ง€ ์•Š์Œ
 
                for(int height=0; height<heightMax; height++){
                    boolean left = (map[width-1][height] == 0) && (map[width-2][height] == 0);
                    boolean right = (map[width+1][height] == 0) && (map[width+2][height] == 0);
                    if(map[width][height] == 1 && left && right ){
                        count++;
                    }
                }
            }
            //System.out.println(Arrays.deepToString(map));
 
            System.out.println("#" + test_case + " " + count);
        }
         
    }
}

 

๋ฐ˜์‘ํ˜•
  • ๋„ค์ด๋ฒ„ ๋ธ”๋Ÿฌ๊ทธ ๊ณต์œ ํ•˜๊ธฐ
  • ํŽ˜์ด์Šค๋ถ ๊ณต์œ ํ•˜๊ธฐ
  • ํŠธ์œ„ํ„ฐ ๊ณต์œ ํ•˜๊ธฐ
  • ๊ตฌ๊ธ€ ํ”Œ๋Ÿฌ์Šค ๊ณต์œ ํ•˜๊ธฐ
  • ์นด์นด์˜คํ†ก ๊ณต์œ ํ•˜๊ธฐ