Skip to content

Commit b978f90

Browse files
authored
Merge pull request #484 from cheonjiwan/func
생태학
2 parents 5b35deb + d1d9d60 commit b978f90

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
}

0 commit comments

Comments
 (0)