-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
executable file
·65 lines (58 loc) · 1.54 KB
/
Main.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package Potitos;
import java.util.*;
public class Main {
static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
int potitos = scan.nextInt();
while (potitos!=0) {
_potitos(potitos);
potitos = scan.nextInt();
}
}
private static void _potitos(int potitos) {
LinkedList<String> SI = new LinkedList<String>();
LinkedList<String> NO = new LinkedList<String>();
for (int i = 0; i < potitos; i++) {
String leGusta = scan.next();
String ingrediente = scan.next();
if (leGusta.equals("SI:")) {
while (!ingrediente.equals("FIN")) {
SI.add(ingrediente);
Iterator<String> it = NO.iterator();
while (it.hasNext()) {
String helper = (String) it.next();
if (helper.equals(ingrediente)) {
it.remove();
}
}
ingrediente = scan.next();
}
} else {
while (!ingrediente.equals("FIN")) {
boolean inList = false;
boolean inList2 = false;
for (String aux : SI) {
if (aux.equals(ingrediente))
inList = true;
}
for (String aux : NO) {
if (aux.equals(ingrediente))
inList2 = true;
}
if (!inList && !inList2) {
NO.add(ingrediente);
}
ingrediente = scan.next();
}
}
}
Collections.sort(NO);
StringBuilder stb = new StringBuilder();
for (String aux : NO)
stb.append(aux + " ");
if (stb.length() > 0)
stb.delete(stb.length() - 1, stb.length());
String res = stb.toString();
System.out.println(res);
}
}