-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA185.java
More file actions
47 lines (36 loc) · 1.32 KB
/
A185.java
File metadata and controls
47 lines (36 loc) · 1.32 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
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class A185 {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int casos = sc.nextInt();
while (casos != 0) {
Set<String> ingredientesSI = new TreeSet<>();
Set<String> ingredientesNO = new TreeSet<>();
for (int i = 0; i < casos; i++) {
String palabra = sc.next();
String alimentos = sc.next();
while (!alimentos.equals("FIN") && palabra.equals("SI:")) {
ingredientesSI.add(alimentos);
alimentos = sc.next();
}
while (!alimentos.equals("FIN") && palabra.equals("NO:")) {
ingredientesNO.add(alimentos);
alimentos = sc.next();
}
ingredientesNO.removeAll(ingredientesSI);
}
Iterator<String> i = ingredientesNO.iterator();
if (i.hasNext()) {
System.out.print(i.next());
}
while (i.hasNext()) {
System.out.print(" " + i.next());
}
System.out.println();
casos = sc.nextInt();
}
}
}