fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.text.*;
  4. import java.io.*;
  5. import java.util.regex.Pattern;
  6.  
  7. class Ideone
  8. {
  9. static HashMap<String, Integer> vocabulary = new HashMap<String, Integer>();
  10. static Scanner sc = new Scanner(System.in);
  11.  
  12. public static boolean isEngLetter(char c){
  13. return 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z';
  14. }
  15.  
  16. public static boolean isWord(String s){
  17. for(int i = 0; i < s.length(); i++){
  18. if(!(
  19. isEngLetter(s.charAt(i)) ||
  20. Character.isDigit(s.charAt(i)) ||
  21. Pattern.matches("\\p{Punct}", s)
  22. )
  23. )
  24. {
  25. return false;
  26. }
  27. }
  28. return true;
  29. }
  30.  
  31. public static String toAlpha(String s){
  32. return s.replaceAll("[^a-zA-Z]","");
  33. }
  34.  
  35. public static void main (String[] args) throws java.lang.Exception
  36. {
  37. while(sc.hasNext()){
  38. String s = sc.next();
  39. if(isWord(s)){
  40. s = toAlpha(s);
  41. if(!s.isEmpty()){
  42. vocabulary.put(s, vocabulary.containsKey(s) ? vocabulary.get(s) + 1 : 1);
  43. }
  44. }
  45. }
  46. int sum = 0;
  47. for(int value : vocabulary.values()){
  48. sum += value;
  49. }
  50. NumberFormat formatter = new DecimalFormat("#0.0000");
  51. for(String s : vocabulary.keySet()){
  52. System.out.println(s + " " + formatter.format((double)vocabulary.get(s)/sum));
  53. }
  54. }
  55. }
Success #stdin #stdout 0.21s 321472KB
stdin
   Inside out have the times
      turned.
      Now in Rim [people] scream
      under Kuman sabers, 495 and Volodimir [screams]
      under wounding blows.
      Woe and anguish to you,
      [Volodimir]
      son of Gleb!

      Great prince Vsevolod!
      Do you not think of flying here
      from 500 afar
      to safeguard the paternal golden
      throne?
      For you can with your oars
      scatter in drops the Volga, 505 and with your helmets
      scoop dry the Don.
      If you were here,
      a female slave would fetch
      one nogata, 510 and a male slave,
      one rezana;
      for you can shoot on land live
      bolts-
      [these are] the bold sons of
      Gleb! 515 You turbulent Rurik, and [you]
      David!
      Were not your men's gilt helmets
      afloat on blood?
      Do not your brave knights roar 520 like
      bulls
      wounded by tempered sabers
      in the field unknown?
      Set your feet, my lords,
      in your stirrups of gold
      to avenge the wrong of our time, 525 the Russian land,
      and the wounds of Igor,
      turbulent son of Svyatoslav.

      Eight-minded Yaroslav of Galich!
      You sit high on your gold-forged
      throne; 530 you have braced the Hungarian
      mountains
      with your iron troops;
      you have barred the [Hungarian]
      king's 535 path;
      you have closed the Danube's
      gates,
      hurling weighty missiles over
      the clouds, 540 spreading your courts to the
      Danube.
      Your thunders range
      over lands;
      you open Kiev's gates;
      from the paternal golden throne
      you shoot at sultans 545 beyond the lands.
      Shoot [your arrows], lord,
      at Konchak, the pagan slave,
      to avenge the Russian land,
      and the wounds of Igor, 550 turbulent son of Svyatoslav!

      And you, turbulent Roman, and
      Mstislav!
      A brave thought 555 carries your minds to deeds.
      On high you soar to deeds
      in your turbulence,
      like the falcon
      that rides the winds
      as he strives in turbulence 560 to overcome the bird.
      For you have iron breastplates
      under Latin helmets;
      these have made the earth
      rumble,
      and many nations- 565 Hins, Lithuanians, Yatvangians,
      Dermners, and Kumans-
      have dropped their spears
      and bowed their heads
      beneath those steel swords.
570 But already, [O] Prince Igor,
      the sunlight has dimmed,
      and, not goodly, the tree sheds
      its
      foliage. 575 Along the Ros and the Sula
      the towns have been distributed;
      and Igor's brave troops
      cannot be brought back to life!
      The Don, Prince, calls you, 580 and summons the princes to
      victory.
      The brave princes, descendants
      of
      Oleg,
      have hastened to fight. 585 Ingvar and Vsevolod,
      and all three sons of Mstislav,
      six-winged [hawks?] of no mean
      brood!
      Not by victorious sorts
      did you grasp your patrimonies. 590 Where, then, are your golden
      helmets,
      and Polish spears, and shields?
      Bar the gates of the prairie
      with your sharp arrows
      to avenge the Russian land
      and the wounds of Igor,
      turbulent son of Svyatoslav.

      No longer indeed does the Sula
      flow
      in silvery streams
      for [the defense of] the town of
      Pereyaslavl;
      and the Dvina, too,
      flows marsh-like
      for the erstwhile dreaded
      townsmen of Polotsk
      to the war cries of pagans. 
stdout
been 0.0027
thought 0.0027
scream 0.0027
your 0.0379
rides 0.0027
anguish 0.0027
these 0.0027
would 0.0027
missiles 0.0027
sorts 0.0027
you 0.0325
deeds 0.0027
spreading 0.0027
dreaded 0.0027
as 0.0027
at 0.0054
male 0.0027
safeguard 0.0027
victorious 0.0027
A 0.0027
Set 0.0027
be 0.0027
overcome 0.0027
descendants 0.0027
gold 0.0027
minds 0.0027
The 0.0054
grasp 0.0027
are 0.0027
defense 0.0027
weighty 0.0027
does 0.0027
by 0.0054
bulls 0.0027
But 0.0027
think 0.0027
a 0.0054
knights 0.0027
one 0.0054
Woe 0.0027
Yaroslav 0.0027
many 0.0027
the 0.1030
Great 0.0027
bowed 0.0027
turbulent 0.0136
calls 0.0027
closed 0.0027
Your 0.0027
to 0.0352
under 0.0081
open 0.0027
did 0.0027
Russian 0.0081
wounding 0.0027
shoot 0.0054
has 0.0027
female 0.0027
those 0.0027
wounds 0.0081
hastened 0.0027
town 0.0027
For 0.0054
its 0.0027
Do 0.0054
bold 0.0027
Not 0.0027
longer 0.0027
Now 0.0027
flying 0.0027
towns 0.0027
Latin 0.0027
mountains 0.0027
scoop 0.0027
Volodimir 0.0027
for 0.0081
avenge 0.0081
Inside 0.0027
throne 0.0027
back 0.0027
sabers 0.0027
gates 0.0027
not 0.0108
drops 0.0027
breastplates 0.0027
flows 0.0027
tempered 0.0027
live 0.0027
prince 0.0027
sit 0.0027
over 0.0054
war 0.0027
indeed 0.0027
with 0.0108
summons 0.0027
Ingvar 0.0027
Rim 0.0027
iron 0.0054
he 0.0027
sultans 0.0027
dropped 0.0027
courts 0.0027
beyond 0.0027
troops 0.0027
three 0.0027
sons 0.0054
pagan 0.0027
golden 0.0081
brave 0.0108
roar 0.0027
flow 0.0027
in 0.0190
townsmen 0.0027
made 0.0027
streams 0.0027
Polotsk 0.0027
turbulence 0.0027
spears 0.0027
field 0.0027
afar 0.0027
If 0.0027
Shoot 0.0027
braced 0.0027
steel 0.0027
erstwhile 0.0027
brought 0.0027
falcon 0.0027
range 0.0027
our 0.0027
out 0.0027
slave 0.0027
Sula 0.0054
scatter 0.0027
have 0.0244
barred 0.0027
wrong 0.0027
sharp 0.0027
sunlight 0.0027
fetch 0.0027
princes 0.0027
cannot 0.0027
thunders 0.0027
heads 0.0027
Were 0.0027
arrows 0.0027
that 0.0027
high 0.0054
Prince 0.0027
son 0.0108
from 0.0054
strives 0.0027
oars 0.0027
helmets 0.0054
all 0.0027
cries 0.0027
beneath 0.0027
like 0.0054
tree 0.0027
dry 0.0027
my 0.0027
were 0.0027
And 0.0027
Ros 0.0027
soar 0.0027
sheds 0.0027
here 0.0027
no 0.0027
Kuman 0.0027
their 0.0054
afloat 0.0027
silvery 0.0027
can 0.0054
times 0.0027
hurling 0.0027
winds 0.0027
and 0.0542
of 0.0515
land 0.0054
gilt 0.0027
on 0.0081
wounded 0.0027
No 0.0027
Polish 0.0027
prairie 0.0027
stirrups 0.0027
Bar 0.0027
carries 0.0027
mean 0.0027
earth 0.0027
Hungarian 0.0027
Along 0.0027
You 0.0054
paternal 0.0054
On 0.0027