문제 풀이 및 개발 공간

[백준] 25757번 임스와 함께하는 미니게임 (silver 5 본문

카테고리 없음

[백준] 25757번 임스와 함께하는 미니게임 (silver 5

gomduri43 2024. 3. 20. 16:19

import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
        StringTokenizer st=new StringTokenizer(br.readLine());
        int n=Integer.valueOf(st.nextToken());
        char game=st.nextToken().charAt(0);

        int people=0;
        if(game=='Y'){
            people=2;
        }
        else if(game=='F'){
            people=3;
        }
        else if(game=='O'){
            people=4;
        }

        int answer=0;
        int temp=0;
        
        //동일인과 같이 게임 못함.
        //안온사람 오면 체크하고 temp++;
        //temp포함 임스랑 인원이 맞으면 한게임++;
        //이미 dict에 저장되어 동일인은 계속 무시하게 되므로, 계속 진행하면 정답.
        HashMap<String, Boolean> dict=new HashMap<>();
        for(int i=0; i<n; i++){
            String a=br.readLine();
            if(dict.get(a)==null){
                temp++;
                dict.put(a,true);
            }

            if(temp==people-1){
                answer++;
                temp=0;
            }
        }
        bw.write(answer+"");
        bw.flush();


    }
}