File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .io .*;
2+ import java .util .*;
3+
4+ public class Main {
5+ public static void main (String [] args ) throws IOException {
6+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
7+
8+ HashMap <String ,Integer > map = new HashMap <>();
9+ int total =0 ;
10+ while (true ) {
11+ String name = br .readLine ();
12+ if (name == null || name .length () == 0 ) {
13+ break ;
14+ }
15+
16+ if (!map .containsKey (name ))
17+ map .put (name , 1 );
18+ else
19+ map .put (name ,map .get (name )+1 );
20+
21+ total ++;
22+ }
23+ ArrayList <Data > all = new ArrayList <>();
24+ for (String cur : map .keySet ()) {
25+ all .add (new Data (cur ,(double )map .get (cur )/total ));
26+ }
27+
28+ Collections .sort (all , new Comparator <Data >() {
29+ @ Override
30+ public int compare (Main .Data a , Main .Data b ) {
31+ return a .name .compareTo (b .name );
32+ }
33+ });
34+
35+ StringBuilder sb = new StringBuilder ();
36+ for (Data cur : all ) {
37+ sb .append (cur .name +" " +String .format ("%.4f" ,cur .num *100 )+'\n' );
38+ }
39+
40+ System .out .println (sb .toString ());
41+ }
42+
43+ static class Data {
44+ String name ;
45+ double num ;
46+ Data (String name , double num ){
47+ this .name = name ;
48+ this .num = num ;
49+ }
50+ }
51+
52+ }
You can’t perform that action at this time.
0 commit comments