FileDocCategorySizeDatePackage
Perm.javaAPI DocExample1445Tue Dec 12 18:59:42 GMT 2000None

Perm

public class Perm extends Object

Fields Summary
Constructors Summary
Methods Summary
private static java.lang.Stringalphabetize(java.lang.String s)

        int count[] = new int[256];
        int len = s.length();
        for (int i=0; i<len; i++)
            count[s.charAt(i)]++;
        StringBuffer result = new StringBuffer(len);
        for (char c='a"; c<='z"; c++)
            for (int i=0; i<count[c]; i++)
                result.append(c);
        return result.toString();
    
public static voidmain(java.lang.String[] args)

        int minGroupSize = Integer.parseInt(args[1]);
 
        // Read words from file and put into simulated multimap
        Map m = new HashMap();
        try {
            BufferedReader in =
                   new BufferedReader(new FileReader(args[0]));
            String word;
            while((word = in.readLine()) != null) {
                String alpha = alphabetize(word);
                List l = (List) m.get(alpha);
                if (l==null)
                    m.put(alpha, l=new ArrayList());
                l.add(word);
            }
        } catch(IOException e) {
            System.err.println(e);
            System.exit(1);
        }

        // Print all permutation groups above size threshold
        for (Iterator i = m.values().iterator(); i.hasNext(); ) {
            List l = (List) i.next();
            if (l.size() >= minGroupSize)
                System.out.println(l.size() + ": " + l);
        }