import java.io.*; import java.util.*; public class crabbles { Scanner in = new Scanner(System.in); /* Set to true to test */ static boolean test = false; HashSet dictionary = new HashSet(); public String canon(char[] s) { Arrays.sort(s); return new String(s); } public static void main(String[] args) { new crabbles().solve(); } public void solve() { if(test) { String s = "11\ndab\nhappy\nsad\ngreen\nmistake\ngoblin\nhapless\nthrough\njoint\nhole\nfin\n1\n8\ng 5\no 2\ne 3\nt 1\ni 2\nh 3\nl 2\nr 3"; in = new Scanner(s); } // read in the dictionary int num_dict_words = Integer.parseInt(in.nextLine()); // canonicalize each word and put it in the dictionary for(; num_dict_words>0; num_dict_words--) { dictionary.add(canon(in.nextLine().toCharArray())); } // now do each hand separately int num_hands = Integer.parseInt(in.nextLine()); for(; num_hands > 0; num_hands--) { doCase(); } } public void doCase() { // read in number of tiles, read in each tile's value and store in an array // bitmask necessary? int num_tiles = Integer.parseInt(in.nextLine()); char[] letters = new char[num_tiles]; int[] scores = new int[num_tiles]; // read in and save the letters and scores for(int i=0; i best_score) { if(dictionary.contains(canon(temp_word.toString().toCharArray()))) { best_score = temp_score; } } } System.out.println(best_score); } }