-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbes.java
More file actions
50 lines (46 loc) · 1.37 KB
/
bes.java
File metadata and controls
50 lines (46 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.*;
import java.io.*;
public class bes {
public static void main(String [] args) {
Scanner scan = new Scanner(System.in);
while(scan.hasNextLine()) {
TreeMap<String,PriorityQueue<String>> map = new TreeMap<String,PriorityQueue<String>>();
PriorityQueue<String> copy = new PriorityQueue<String>();
String s = scan.nextLine();
if(s.equals("0")) {
break;
}
int numlines = Integer.parseInt(s);
System.out.println();
for(int i=0;i<numlines;i++) {
s = scan.nextLine();
String [] array = s.split(" ");
String name = array[0];
for(int j=1;j<array.length;j++) {
String key = array[j];
PriorityQueue<String> pq = new PriorityQueue<String>();
if(map.containsKey(key) == false) {
pq.add(name);
map.put(key,pq);
}
else {
pq = map.get(key);
pq.add(name);
map.put(key,pq);
}
}
}
String [] keys = new String[map.size()];
String [] values = new String[map.size()];
map.keySet().toArray(keys);
for(int i=0;i<keys.length;i++) {
System.out.print(keys[i]+" ");
PriorityQueue<String> t= map.get(keys[i]);
while(!t.isEmpty()){
System.out.print(t.poll()+" ");
}
System.out.println();
}
}
}
}