-
Notifications
You must be signed in to change notification settings - Fork 15
/
p291.java
50 lines (39 loc) · 1.47 KB
/
p291.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
import java.util.*;
public class p291 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int lineas;
String[] palabras;
TreeMap<String, TreeSet<Integer>> cruzadas;
while (true) {
lineas = s.nextInt();
if (lineas == 0) break;
s.nextLine();
cruzadas = new TreeMap<>();
for (int i = 1; i <= lineas; i++) {
palabras = s.nextLine().split(" ");
for (int j = 0; j < palabras.length; j++) {
if (palabras[j].length() > 2) {
palabras[j] = palabras[j].toLowerCase();
if (!cruzadas.containsKey(palabras[j])) {
cruzadas.put(palabras[j], new TreeSet<>(Arrays.asList(i)));
}
else {
TreeSet<Integer> aux = cruzadas.get(palabras[j]);
aux.add(i);
cruzadas.put(palabras[j], aux);
}
}
}
}
for (Map.Entry<String, TreeSet<Integer>> entry : cruzadas.entrySet()) {
System.out.print(entry.getKey());
for (Integer n : entry.getValue()) {
System.out.print(" " + n);
}
System.out.println();
}
System.out.println("----");
}
}
}