새소식

Algorithm/BOJ

(JAVA) [BOJ]백준 25757번, 임스와 함께하는 미니게임

  • -
728x90

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

 

25757번: 임스와 함께하는 미니게임

첫 번째 줄에는 사람들이 임스와 같이 플레이하기를 신청한 횟수 $N$과 같이 플레이할 게임의 종류가 주어진다. $(1 \le N \le 100\,000)$ 두 번째 줄부터 $N$개의 줄에는 같이 플레이하고자 하는 사람들

www.acmicpc.net

25757, 임스와 함께하는 미니게임

[ 난이도 : 실버  5]

이번 문제는 간단한 구현 문제이다.

Process

input

: 함께 게임을 할 사람의 수 N 과 게임의 종류인 game = Y 를 받아주고 중복을 제거하기 위해 HashSet 을

사용해 주었다.

static int N, playerNum;
static String game;
static String[] player;
static HashSet<String> H = new HashSet<>();

static void input() 
{
    N = scan.nextInt();
    game = scan.next();

    while(N-- > 0)
    {
        H.add(scan.nextLine());
    }
}

구현

: 우선 게임의 종류를 switch 를 통해 playerNum 을 계산해 주었다. 

이때 플레이어의 수는 임스를 제외한 사람의 수이기 때문에 모두 -1 을 한 값을 주었다.

최대한 많이, 겹치지 않게 게임을 진행해야 하기 때문에 게임을 진행한 사람은 모두 배제하면 된다.

즉, 사람의 수를 플레이어의 수로 나눈 몫을 출력해주면 된다.

static void pro() 
{  
    playerNum = 0;
    switch(game)
    {
        case "Y" : 
            playerNum = 1;
            break;
        case "F" : 
            playerNum = 2;
            break;
        case "O" : 
            playerNum = 3;
            break;
        default : 
            break;
    }

    System.out.println(H.size() / playerNum);
}

전체 코드

전체 코드는 아래와 같다.

static int N, playerNum;
static String game;
static String[] player;
static HashSet<String> H = new HashSet<>();

static void input() 
{
    N = scan.nextInt();
    game = scan.next();

    while(N-- > 0)
    {
        H.add(scan.nextLine());
    }
}

static void pro() 
{  
    playerNum = 0;
    switch(game)
    {
        case "Y" : 
            playerNum = 1;
            break;
        case "F" : 
            playerNum = 2;
            break;
        case "O" : 
            playerNum = 3;
            break;
        default : 
            break;
    }

    System.out.println(H.size() / playerNum);
}

public static void main(String[] args) 
{
   input();
   pro();
}

 

 

728x90
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.