Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges’ favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.
This year, they decide to leave this lovely job to you.
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) – the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.
A test case with N = 0 terminates the input and this test case is not to be processed.
For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.
WU, Jiazhi
ZJCPC2004
嗯,接觸的第一道字典樹題目 gdkoi被虐以后想了很多,看來還是努力比較實在,就從頭開始了
字典樹顧名思義就是一棵樹,它以字母也不僅僅以字母作為節(jié)點,相比哈希能節(jié)省較多的空間,然后查找的復雜度只與查詢字符串的長度有關
題目要求找出現(xiàn)最多的單詞,那么開一棵trie然后加單詞就行了,加完所有單詞遍歷一下。其實也是可以插入的同時查詢最大值的,跑得賊快
新聞熱點
疑難解答