forked from improper4/uva
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUVa00156_Ananagrams.java
48 lines (40 loc) · 1.42 KB
/
UVa00156_Ananagrams.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
package uva;
/* USER: 46724 (sfmunera) */
/* PROBLEM: 92 (156 - Ananagrams) */
/* SUBMISSION: 08518432 */
/* SUBMISSION TIME: 2011-01-18 20:11:24 */
/* LANGUAGE: 2 */
import java.util.*;
public class UVa00156_Ananagrams {
public static void main(String[] args) {
try {
Scanner in = new Scanner(System.in);
ArrayList<String> dict = new ArrayList<String>();
while (true) {
String word = in.next();
if (word.equals("#")) break;
dict.add(word);
}
Collections.sort(dict);
for (int i = 0; i < dict.size(); ++i) {
char[] w1 = dict.get(i).toLowerCase().toCharArray();
Arrays.sort(w1);
boolean isanagram = false;
for (int j = 0; j < dict.size(); ++j) {
if (i != j) {
char[] w2 = dict.get(j).toLowerCase().toCharArray();
Arrays.sort(w2);
if (String.valueOf(w1).equals(String.valueOf(w2))) {
isanagram = true;
break;
}
}
}
if (!isanagram) System.out.println(dict.get(i));
}
} catch (Exception e) {
//e.printStackTrace();
System.exit(0);
}
}
}