Guest User

Untitled

a guest
Jan 4th, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. // Read words from file and put into a simulated multimap
  2. Map<String, List<String>> m = new HashMap<String, List<String>>();
  3.  
  4. try {
  5. Scanner s = new Scanner(new File(args[0]));
  6. while (s.hasNext()) {
  7. String word = s.next();
  8. String alpha = alphabetize(word);
  9. List<String> l = m.get(alpha);
  10. if (l == null)
  11. m.put(alpha, l=new ArrayList<String>());
  12. l.add(word);
  13. }
  14. } catch (IOException e) {
  15. System.err.println(e);
  16. System.exit(1);
  17. }
  18.  
  19. // Print all permutation groups above size threshold
  20. for (List<String> l : m.values())
  21. if (l.size() >= minGroupSize)
  22. System.out.println(l.size() + ": " + l);
  23. }
  24.  
  25. private static String alphabetize(String s) {
  26. char[] a = s.toCharArray();
  27. Arrays.sort(a);
  28. return new String(a);
  29. }
Add Comment
Please, Sign In to add comment