import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Scanner; import java.util.TreeMap; public class Trie { Scanner in = new Scanner(System.in); Map myMap = new TreeMap(); public class TreeNode{ char value; TreeNode leftChild; TreeNode rightChild; TreeNode parent; boolean complete; public TreeNode(char c){ value=c; complete=false; } } public void go(){ List trees = new ArrayList(); String s =""; while (true){ s = in.nextLine(); if (s.equals("END")){break;} trees.add(s); } for (int i=0; i counts = new TreeMap(); for (int j=0; j entry: counts.entrySet()){ int numNodes = 0; for (int k=0; kmax){max=c;} } List solutions = new ArrayList(); for (Map.Entry entry: counts.entrySet()){ int numNodes = 0; for (int k=0; k sol2 = new ArrayList(); int minLength=Integer.MAX_VALUE; // for (int k=0; k=s.length()-1){return;} char c = s.charAt(i+1); if (t.complete && t.parent==null){return;} if (t.complete){fromRoot(s, i, t.parent, left);} else if (c=='#' && left){ t.leftChild=null; fromRoot(s, i+1, t, false);} else if(c=='#' &&!left){ t.rightChild = null; t.complete=true; fromRoot(s, i+1, t.parent, false); } else if(left){ t.leftChild = new TreeNode(c); myMap.put(i+1, t.leftChild); t.leftChild.parent = t; fromRoot(s, i+1, t.leftChild, true); } else{ t.rightChild = new TreeNode(c); myMap.put(i+1, t.rightChild); t.rightChild.parent = t; t.complete=true; fromRoot(s, i+1, t.rightChild, true); } } public String findSubtree(TreeNode t){ if (t==null){return "#";} char sub = t.value; return sub + findSubtree(t.leftChild) + findSubtree(t.rightChild); } // public String findSubtree(String s, int i){ // TreeNode t = myMap.get(i); // int firstLevel = getLevel(t, myMap.get(0), 1); // for (int j=0; j=secondLevel && !t.equals(n) && j>i){ // return s.substring(i, j); // } // } // } // // return s; // // } public static void main(String[] args){ Trie t = new Trie(); t.go(); } }