킹,퀸,룩,비숍,나이트,폰

곽지욱·2023년 9월 6일

BOJ

목록 보기
10/69
post-thumbnail

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

  • 본문에 나와 있듯이 각 체스말들의 개수는 고정되어있고, 입력으로는 현재 갖고 있는 말의 개수를 입력받는다
  • 그래서 실제 필요한 체스말의 개수를 맞추어 그 차를 구하면 되는 것
  1. 각, 체스말의 변수를 선언하여 초기 값으로 원래 정상적인 말의 개수를 설정 한 다음, 스캐너를 이용하여 수를 입력받고 입력받은 수들을 각 체스말에 맞추어 해당 변수에서 빼면 된다.
import java.util.Scanner;

public class chess {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int king = 1;
        int queen = 1;
        int rook = 2;
        int bishop = 2;
        int knight =2;
        int pawn =8;

        king = king - in.nextInt();
        queen = queen - in.nextInt();
        rook = rook - in.nextInt();
        bishop = bishop - in.nextInt();
        knight = knight - in.nextInt();
        pawn = pawn - in.nextInt();

        // 참고로 출력형식을 보면 각 변수들사이에 공백으로 구분 된한 줄로 출력해야한다.
        // 즉, 개행(줄바꿈)이 발생하는 println을 쓰면 안된다.
        System.out.print(king + " ");
        System.out.print(queen + " ");
        System.out.print(rook + " ");
        System.out.print(bishop + " ");
        System.out.print(knight + " ");
        System.out.print(pawn);
    }
}

0개의 댓글