31 lines
1.0 KiB
Java
31 lines
1.0 KiB
Java
import java.net.*;
|
|
import java.io.*;
|
|
import java.util.*;
|
|
|
|
public class WordsOfEqChars {
|
|
public static void main(String[] args) throws IOException {
|
|
URL url = new URL("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt");
|
|
InputStreamReader isr = new InputStreamReader(url.openStream());
|
|
BufferedReader reader = new BufferedReader(isr);
|
|
|
|
Map<String, Collection<String>> anagrams = new HashMap<String, Collection<String>>();
|
|
String word;
|
|
int count = 0;
|
|
while ((word = reader.readLine()) != null) {
|
|
char[] chars = word.toCharArray();
|
|
Arrays.sort(chars);
|
|
String key = new String(chars);
|
|
if (!anagrams.containsKey(key))
|
|
anagrams.put(key, new ArrayList<String>());
|
|
anagrams.get(key).add(word);
|
|
count = Math.max(count, anagrams.get(key).size());
|
|
}
|
|
|
|
reader.close();
|
|
|
|
for (Collection<String> ana : anagrams.values())
|
|
if (ana.size() >= count)
|
|
System.out.println(ana);
|
|
}
|
|
}
|