🐣 알고리즘 삐약/💻 백준 삐약

100 삐약 : 백준 7785 | 회사에 있는 사람 [바킹독| HASH |JAVA]

우주수첩 2024. 10. 31. 16:19
728x90

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

 

package BKD_0x15_Hash;

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

public class BOJ_7785 {
    public static void main(String[] args) throws IOException {
        HashSet<String> set = new HashSet<>();

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());

        for(int i=0;i<N;i++){
            StringTokenizer st = new StringTokenizer(br.readLine());
            String name = st.nextToken();
            String eol = st.nextToken();

            if(eol.equals("enter")) {
                set.add(name);
            }else{
                set.remove(name);
            }
        }

        Object[] arr = set.toArray();
        Arrays.sort(arr, Collections.reverseOrder());

        for(Object str : arr){
            System.out.println(str);
        }



    }
}

 

 

  • HashSet을 사용하여 구현

 

# 배열 역순 정렬

  Arrays.sort(arr, Collections.reverseOrder());

 

 

728x90