import edu.princeton.cs.algs4.*; public class FrequencyCounter { public static void main(String[] args)//还是用终端吧 { int minlen = Integer.parseInt(args[0]); ST<String, Integer> st = new ST<String, Integer>(); while(!StdIn.isEmpty()) { String word = StdIn.readString(); if(word.length() < minlen) continue; if(!st.contains(word)) st.put(word, 1); else st.put(word, st.get(word) + 1); } String max = ""; st.put(max,0); for(String word : st.keys()) { if(st.get(word) > st.get(max)) max = word; } StdOut.println(max + " " + st.get(max)); } }
372 A symbol-table client
猜你喜欢
转载自www.cnblogs.com/w-j-c/p/9152134.html
今日推荐
周排行