Progamming/BAEK JOON > 백준의 알고리즘

[백준] 3003번 : 킹, 퀸, 룩, 비숍, 나이트, 폰 - JAVA

코딩밤 2023. 2. 7. 15:16
300x250

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

 

3003번: 킹, 퀸, 룩, 비숍, 나이트, 폰

첫째 줄에 동혁이가 찾은 흰색 킹, 퀸, 룩, 비숍, 나이트, 폰의 개수가 주어진다. 이 값은 0보다 크거나 같고 10보다 작거나 같은 정수이다.

www.acmicpc.net

 

문제

백준 3003번 문제 이미지

 


알고리즘 접근방법

체스 총 16피스 개수가 정해져있는 체스말들

입력한 숫자가 동혁이가 찾은 체스말의 개수

기존 룰의 체스말과 동혁이의 체스말을 대조해

개수를 맞추어 보는 문제

 

풀이

 

import java.util.Scanner;
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int king = 1;
        int queen = 1;
        int rooks = 2;
        int bishops = 2;
        int knights = 2;
        int pawns = 8;

        king = king - sc.nextInt();
        queen = queen - sc.nextInt();
        rooks = rooks - sc.nextInt();
        bishops = bishops - sc.nextInt();
        knights = knights - sc.nextInt();
        pawns = pawns - sc.nextInt();
        
        System.out.print(king + " ");
        System.out.print(queen + " ");
        System.out.print(rooks + " ");
        System.out.print(bishops + " ");
        System.out.print(knights + " ");
        System.out.print(pawns);
        // " "은 공백(띄어쓰기)를 주기 위함이다.
        // println은 자동줄바꿈이 되기에 print를 사용했다.

    }
}

 

예제 출력을 보면 공백으로 이루어진 한 줄로 출력해야 한다

300x250