forked from improper4/uva
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUVa00123_SearchingQuickly.java
62 lines (52 loc) · 1.44 KB
/
UVa00123_SearchingQuickly.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
package uva;
/* USER: 46724 (sfmunera) */
/* PROBLEM: 59 (123 - Searching Quickly) */
/* SUBMISSION: 10058358 */
/* SUBMISSION TIME: 2012-04-30 18:22:10 */
/* LANGUAGE: 2 */
import java.util.*;
import java.io.*;
public class UVa00123_SearchingQuickly{
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
Set<String> ignored = new HashSet<String>();
List<String> titles = new ArrayList<String>();
String line;
while (true) {
line = in.readLine().trim();
if (line.equals("::"))
break;
ignored.add(line.toLowerCase());
}
while ((line = in.readLine()) != null) {
titles.add(line.trim().toLowerCase());
}
Set<String> noIgnored = new TreeSet<String>();
for (String t : titles) {
String[] parts = t.split("[ ]+");
for (String s : parts)
if (!ignored.contains(s))
noIgnored.add(s);
}
for (String s : noIgnored) {
for (String t : titles) {
String[] parts = t.split("[ ]+");
for (int i = 0; i < parts.length; ++i) {
if (s.equals(parts[i])) {
for (int j = 0; j < parts.length; ++j) {
if (j > 0)
System.out.print(" ");
if (i != j)
System.out.print(parts[j]);
else
System.out.print(parts[j].toUpperCase());
}
System.out.println();
}
}
}
}
in.close();
System.exit(0);
}
}