-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from wwan13/boj/16165
[S3] 16165 걸그룹 마스터 준석이
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |