Archives
Recent Posts
«   2024/05   »
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 31
관리 메뉴

개발도생's Blog

[백준][Java] 15439_Vera and Outfits 본문

BaekJoon

[백준][Java] 15439_Vera and Outfits

개발도생 2022. 12. 9. 19:35

[백준] 15439_Vera and Outfits 문제

 

15439번: Vera and Outfits

Vera owns N tops and N pants. The i-th top and i-th pants have colour i, for 1 ≤ i ≤ N, where all N colours are different from each other. An outfit consists of one top and one pants. Vera likes outfits where the top and pants are not the same colour.

www.acmicpc.net


15439, Vera and Outfits 문제


Vera라는 사람은 N개의 상의와 하의를 가지고 있는데, 상하의 같은 색깔로 세트로 가지고 있다고 한다.

 

근데 상의와 하의를 같은 색상으로 입고 싶지 않다고 코디할 수 있는 경우의 수를 물어본 문제다.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException{

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int N = Integer.parseInt(br.readLine());

        System.out.println(N * (N - 1));
    }
}

먼저 N 값을 입력받기 위해 Bufferedreader 객체를 사용했다.

 

[Java][Class] Bufferedreader

코딩 테스트 문제들을 풀다가 우연히 알게 된 Bufferedreader 객에 대해서 공부해봤다. Bufferedreader Class는, 이름과 같이 버퍼를 사용하는 클래스다. 일반적으로 알고 있던 Scanner Class는 사용자가 값을

nan-o-nuel-do.tistory.com

그리고 버퍼에 저장된 값을 Integer.parseInt() 메서드를 통해 형변환 시켜 정수 타입의 변수에 저장해주었다.

 

저장된 값을 *순열 계산식으로 경우의 수를 구해줬다.

더보기

순열이란,

  • 순서를 정해서 나열하는 것을 뜻한다.
    • 예를 들어, 각기 다른 색깔의 구슬 6개가 들어 있는 주머니에서 3개를 선택해서 순서대로 나열하는 방법은 총 몇 가지 인가를 계산하는 것.

입력 예시
입력해야 되는 값, 출력 값


위와 같은 코드로 제출했을 때,

맞았습니다!!

'BaekJoon' 카테고리의 다른 글

[백준][Java] 15610_Abbey Courtyard  (0) 2022.12.11
[백준][Java] 15552_빠른 A+B  (2) 2022.12.11
[백준][Java] 15232_Rectangles  (1) 2022.12.09
[백준][Java] 15080_Every Second Counts  (1) 2022.12.08
[백준][Java] 15059_Hard choice  (2) 2022.12.08
Comments