[BOJ][C#] 25757 임스와 함께하는 미니게임

LimJaeJun·2023년 11월 19일
0

PS/BOJ

목록 보기
41/108

📕 문제

📌 링크

📗 접근 방식

  • HashSet을 사용하여 중복처리를 하여 참가자 목록을 저장
  • 게임 모드에 따라 최종 참가자 수를 계산합니다.
    • Y : 참가자 목록에 있는 모든 참가자의 수를 출력합니다.
    • F : 참가자 목록에 있는 참가자 수의 절반을 출력합니다.
    • O : 참가자 목록에 있는 참가자 수의 셋째의 절반을 출력합니다.
      최종 결과를 출력합니다.

📘 코드

namespace BOJ_25757
{
    class Program
    {
        static void Main()
        {
            string[] inputs = Console.ReadLine().Split();
            int n = int.Parse(inputs[0]);
            string gameMode = inputs[1];
            int answer = 0;

            HashSet<string> participantList = new HashSet<string>();

            for (int i = 0; i < n; i++)
            {
                string participant = Console.ReadLine();

                participantList.Add(participant);
            }

            switch (gameMode)
            {
                case "Y":
                    answer = participantList.Count;

                    break;
                case "F":
                    answer = (int)Math.Floor((double)participantList.Count/2);
                    
                    break;
                
                case "O":
                    answer = (int)Math.Floor((double)participantList.Count/3);

                    break;
            }

            Console.WriteLine(answer);
        }
    }
}

📙 오답노트

📒 알고리즘 분류

  • 자료 구조
  • 문자열
  • 해시를 사용한 집합과 맵
profile
Dreams Come True

0개의 댓글

관련 채용 정보