Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[S3] 16165 걸그룹 마스터 준석이 #130

Merged
merged 1 commit into from
Dec 10, 2024
Merged

[S3] 16165 걸그룹 마스터 준석이 #130

merged 1 commit into from
Dec 10, 2024

Conversation

wwan13
Copy link
Owner

@wwan13 wwan13 commented Dec 10, 2024

Problem Info

Code

package boj16165;

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

public class Main {

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) {
        String[] nm = readLine().split(" ");
        int n = Integer.parseInt(nm[0]);
        int m = Integer.parseInt(nm[1]);

        Map<String, List<String>> groupMap = new HashMap<>();
        Map<String, String> memberMap = new HashMap<>();

        for (int i = 0; i < n; i++) {
            String groupName = readLine();
            int memberCount = Integer.parseInt(readLine());

            List<String> members = new ArrayList<>();
            for (int j = 0; j < memberCount; j++) {
                String memberName = readLine();
                members.add(memberName);
                memberMap.put(memberName, groupName);
            }

            Collections.sort(members);
            groupMap.put(groupName, members);
        }

        StringBuilder result = new StringBuilder();
        for (int i = 0; i < m; i++) {
            String query = readLine();
            int queryType = Integer.parseInt(readLine());

            if (queryType == 0) {
                List<String> members = groupMap.get(query);
                for (String member : members) {
                    result.append(member).append("\n");
                }
            } else {
                result.append(memberMap.get(query)).append("\n");
            }
        }

        System.out.print(result);
    }

    private static String readLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Note

@github-actions github-actions bot added data_structures 알고리즘: data_structures hash_set 알고리즘: hash_set labels Dec 10, 2024
@github-actions github-actions bot changed the title solve : 16165 걸그룹 마스터 준석이 [S3] 16165 걸그룹 마스터 준석이 Dec 10, 2024
@wwan13 wwan13 merged commit 9c26119 into main Dec 10, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data_structures 알고리즘: data_structures hash_set 알고리즘: hash_set
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant