-
Notifications
You must be signed in to change notification settings - Fork 0
/
Diner.java
51 lines (44 loc) · 1.32 KB
/
Diner.java
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
51
//Srishti Singhal
import java.io.*;
import java.util.*;
public class Diner{
public static void main(String[] args){
Scanner ob = new Scanner(System.in);
while(ob.hasNextInt()){
int count = ob.nextInt();
TreeMap<String,ArrayList<String>> rbTree = new TreeMap<String,ArrayList<String>>();
ArrayList<String> list = new ArrayList<String>();
if(count == 0){
break;
}
for(int i = 0; i<count ; i++){
String name = ob.next();
String[] lines = ob.nextLine().substring(1).split(" ");
for(int j = 0; j<lines.length; j++){
if(!rbTree.containsKey(lines[j])){
ArrayList<String> in = new ArrayList<>();
in.add(name);
rbTree.put(lines[j],in);
}
else{
ArrayList<String> in = rbTree.get(lines[j]);
in.add(name);
rbTree.put(lines[j],in);
}
}
}
for (Map.Entry<String, ArrayList<String>> entry : rbTree.entrySet()) {
String key = entry.getKey();
ArrayList<String> value = entry.getValue();
Collections.sort(value);
System.out.print(key);
String values = "";
for(String val: value){
values += " "+val;
}
System.out.println(values);
}
System.out.println();
}
}
}