Skip to content

Commit

Permalink
Merge pull request #130 from wwan13/boj/16165
Browse files Browse the repository at this point in the history
[S3] 16165 걸그룹 마스터 준석이
  • Loading branch information
wwan13 authored Dec 10, 2024
2 parents d1a8b19 + fc7c68f commit 9c26119
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions java/src/boj16165/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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);
}
}
}

0 comments on commit 9c26119

Please sign in to comment.