static void Main(string[] args) { int n = Convert.ToInt32(Console.ReadLine()); Trie t = new Trie(); List <int> resulti = new List <int>(); for (int a0 = 0; a0 < n; a0++) { string[] tokens_op = Console.ReadLine().Split(' '); string op = tokens_op[0]; string contact = tokens_op[1]; if (op == "add") { t.insert(contact); } else { resulti.Add(t.startWithPrefixCount(contact)); } } foreach (var item in resulti) { Console.WriteLine(item); } Console.ReadLine(); }
static void Main(string[] args) { string[] keys = { "the", "a", "there", "answer", "any", "by", "bye", "their" }; string[] output = { "Not present in trie", "Present in trie" }; Trie trie = new Trie(); trie.root = new TrieNode(); for (int i = 0; i < keys.Length; i++) { trie.insert(keys[i]); } if (trie.search("the") == true) { Console.WriteLine("the --- " + output[1]); } else { Console.WriteLine("the --- " + output[0]); } if (trie.search("these") == true) { Console.WriteLine("these --- " + output[1]); } else { Console.WriteLine("these --- " + output[0]); } if (trie.search("their") == true) { Console.WriteLine("their --- " + output[1]); } else { Console.WriteLine("their --- " + output[0]); } if (trie.search("thaw") == true) { Console.WriteLine("thaw --- " + output[1]); } else { Console.WriteLine("thaw --- " + output[0]); } }
public static void readFileFromFile(String path) { if (tree == null) { tree = new Trie.Trie(path); } Scanner scanner = new Scanner(path); String info; int count = 0; int man = "男".GetHashCode(); int woman = "女".GetHashCode(); while ((info = scanner.nextLine()) != null) { count++; count %= 9; if (count == 0) { tree.setDescribe(info); tree.insert(); } else { switch (count) { case 1: tree.setQQ(Int32.Parse(info)); break; case 2: tree.setAge(Int32.Parse(info)); break; case 3: int message = info.GetHashCode(); if (message == man) { tree.setSex(true); } else if (message == woman) { tree.setSex(false); } else { tree.setSex(null); } break; case 4: tree.setName(info); break; case 5: tree.setGroupID(Int32.Parse(info)); break; case 6: tree.setGroupName(info); break; case 7: tree.setPrivilege(info); break; case 8: tree.setCreateTime(info); break; } } } }