-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathQ7785.java
50 lines (44 loc) · 1.07 KB
/
Q7785.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
package datastructure2;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;
public class Q7785 {
public static void main(String[] args) {
// TODO Auto-generated method stub
HashMap<String,Integer> hashmap=new HashMap<String,Integer>();
Scanner sc=new Scanner(System.in);
int n;
n=sc.nextInt();
String input=sc.nextLine();
for(int i=0;i<n;i++) {
input=sc.nextLine();
String[] tokens=input.split(" ");
if(!(hashmap.isEmpty())&&(hashmap.containsKey(tokens[0]))) {
if(tokens[1].equals("enter")) {
hashmap.replace(tokens[0], 1);
}
else {
hashmap.remove(tokens[0]);
}
}
else {
if(hashmap.isEmpty()||tokens[1].equals("enter")) {
hashmap.put(tokens[0], 1);
}
else {
hashmap.remove(tokens[0]);
}
}
}
Set<String> set=hashmap.keySet();
ArrayList<String> result=new ArrayList(set);
Collections.sort(result);
int i=result.size()-1;
while(i>=0) {
System.out.println(result.get(i--));
}
}
}