fork download
  1. import java.util.*;
  2. class M{
  3. static Object c(String s){List w=Arrays.asList(s.toLowerCase().split("[^\\w'-]+"));Object r=w;int p=0,x=0;for(Object a:w){p=Collections.frequency(w,r);if(Collections.frequency(w,a)>p)r=a;if(p>x)x=p;}for(Object b:w)if(!b.equals(r)&Collections.frequency(w,b)==p)return"";return r;}
  4.  
  5. public static void main(String[] a){
  6. System.out.println(c("The man walked down the road."));
  7. System.out.println(c("Slowly, he ate the pie, savoring each delicious bite. He felt like he was truly happy."));
  8. System.out.println(c("This sentence has no most frequent word."));
  9. System.out.println(c("\"That's... that's... that is just terrible!\" he said."));
  10. System.out.println(c("The old-fashioned man ate an old-fashioned cake."));
  11. System.out
  12. .println(c("IPv6 looks great, much better than IPv4, except for the fact that IPv6 has longer addresses."));
  13. System.out.println(c("This sentence with words has at most two equal most frequent words."));
  14. }
  15. }
Success #stdin #stdout 0.05s 711168KB
stdin
Standard input is empty
stdout
the
he

that's
old-fashioned
ipv6