fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. private static Map<String, Double> W = new HashMap<String, Double>();
  11. private static Scanner in = new Scanner(System.in);
  12. SortedMap<Double, List<Object>> SW = new TreeMap<Double, List<Object>>();
  13. public static String max(String [] args){
  14. double max = 0;
  15. String res = new String();
  16. for(String a : args){
  17. if(W.containsKey(a)) if(W.get(a) > max){ max = W.get(a); res = a;}
  18. }
  19. return res;
  20. }
  21. public static void main (String[] args) throws java.lang.Exception
  22. {
  23.  
  24. String txt = new String();
  25. long all = 0;
  26. in.useDelimiter("[—,.!:;? \n«»()\"]");
  27. while(in.hasNext()){
  28. txt = in.next();
  29. if(!txt.equals("") && !txt.equals("-")){
  30. String buf = txt.toLowerCase();
  31. if(W.containsKey(buf)){ W.put(buf, W.get(buf) + 1.0); all++;}
  32. else{ W.put(buf, 1.0); all++;}
  33. }
  34. }
  35.  
  36.  
  37. System.out.println(all);
  38. // for(String a : W.keySet()) W.put(a, W.get(a)/all);
  39.  
  40.  
  41. SortedMap<Double, List<Object>> SW = new TreeMap<Double, List<Object>>();
  42.  
  43. for(Object a : W.keySet())
  44. if(SW.containsKey(W.get(a))){
  45. SW.get(W.get(a)).add(a);
  46. }
  47. else{
  48. List<Object> buf = new ArrayList<Object>();
  49. buf.add(a);
  50. SW.put(W.get(a), buf) ;
  51. }
  52. String [] arr = {"the","a","table"};
  53. try{
  54. //System.outmax(arr);
  55. }
  56. catch(Exception e){
  57. System.out.println(e);
  58. }
  59.  
  60. for(Object a : SW.keySet()){
  61. System.out.print(a + " => " );
  62. int n = SW.get(a).size();
  63. for(int i = 0; i < n; i++){
  64. System.out.print(SW.get(a).get(i) + (i == n - 1? ".\n" : ", "));
  65. }
  66. }
  67. }
  68. }
Success #stdin #stdout 0.16s 321344KB
stdin
To be, or not to be? That is the question—
Whether ’tis nobler in the mind to suffer
The slings and arrows of outrageous fortune,
Or to take arms against a sea of troubles,
And, by opposing, end them? To die, to sleep—
No more—and by a sleep to say we end
The heartache and the thousand natural shocks
That flesh is heir to—’tis a consummation
Devoutly to be wished! To die, to sleep.
To sleep, perchance to dream—ay, there’s the rub,
For in that sleep of death what dreams may come
When we have shuffled off this mortal coil,
Must give us pause. There’s the respect
That makes calamity of so long life.
For who would bear the whips and scorns of time,
Th’ oppressor’s wrong, the proud man’s contumely,
The pangs of despised love, the law’s delay,
The insolence of office, and the spurns
That patient merit of th’ unworthy takes,
When he himself might his quietus make
With a bare bodkin? Who would fardels bear,
To grunt and sweat under a weary life,
But that the dread of something after death,
The undiscovered country from whose bourn
No traveler returns, puzzles the will
And makes us rather bear those ills we have
Than fly to others that we know not of?
Thus conscience does make cowards of us all,
And thus the native hue of resolution
Is sicklied o’er with the pale cast of thought,
And enterprises of great pith and moment
With this regard their currents turn awry,
And lose the name of action.—Soft you now,
The fair Ophelia!—Nymph, in thy orisons
Be all my sins remembered.
stdout
276
1.0 => thought, whips, fair, resolution, pangs, cast, suffer, remembered, pith, action, heartache, o’er, pale, you, devoutly, soft, give, natural, lose, them, come, whose, something, himself, delay, ay, must, returns, shocks, flesh, nymph, bodkin, love, against, nobler, turn, dread, sea, long, moment, currents, native, does, after, so, insolence, takes, orisons, mind, spurns, question, may, man’s, more, weary, great, off, wrong, fly, regard, under, thousand, rub, but, country, sicklied, despised, traveler, thy, conscience, arrows, wished, office, enterprises, his, whether, than, from, bare, bourn, those, others, coil, proud, puzzles, might, cowards, shuffled, merit, my, pause, respect, sins, take, contumely, perchance, dream, name, know, arms, unworthy, oppressor’s, law’s, rather, their, slings, dreams, troubles, awry, grunt, calamity, heir, consummation, patient, now, ills, outrageous, scorns, mortal, undiscovered, opposing, fortune, will, fardels, say, quietus, what, sweat, hue, time, he, ophelia.
2.0 => when, would, th’, thus, there’s, by, have, makes, ’tis, die, all, this, who, no, death, for, life, not, end, make, or.
3.0 => in, is, bear, us, with.
4.0 => be, we.
5.0 => sleep, a.
7.0 => that.
12.0 => and.
15.0 => to, of.
20.0 => the.