Notice
Recent Posts
Recent Comments
Link
«   2026/04   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
Tags more
Archives
Today
Total
관리 메뉴

luke

[백준] - 킹, 퀸, 룩, 비숍, 나이트, 폰 (3003) (Java/자바) 본문

알고리즘문제/백준 문제(Java)

[백준] - 킹, 퀸, 룩, 비숍, 나이트, 폰 (3003) (Java/자바)

luke-king 2025. 7. 24. 23:07

문제 : https://www.acmicpc.net/problem/3003

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

문제.


 

 

 

 

 

 

 

 

풀이.


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] arr = {1,1,2,2,2,8};
        int[] res = new int [arr.length];

        for(int i = 0; i < arr.length; i++){
            int[] chk = new int[arr.length];
            chk[i] = sc.nextInt();
            res[i] = arr[i] - chk[i];
            
            System.out.print(res[i]+" ");
        }
        
        sc.close();
    }

}

이번 문제는 백준 "킹, 퀸, 룩, 비숍, 나이트, 폰" 문제다.

문제는 크게 어려움 없어 바로 설명하겠다.

 

1. 체스의 피스는 1,1,2,2,2 가 고정이며 총 8개 이므로 1,1,2,2,2,8을 담고 있는 배열을 생성해준다.

 

2. 값을 담기 위한 res[] 배열도 생성해준다.

 

3. for문 생성 후 입력값을 위한 chk[] 배열 생성해 입력 값을 넣어 준다.

 

4. 마지막으로 res[] 배열에 arr[] 값과 chk[] 값을 빼주면 끝이다.