-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHardwoodSpecies.java
More file actions
38 lines (32 loc) · 996 Bytes
/
HardwoodSpecies.java
File metadata and controls
38 lines (32 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.treemap;
import java.io.*;
import java.util.*;
//uva 10226
public class HardwoodSpecies {
static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
static TreeMap<String, Integer> mapping;
static int total = 0;
public static void main(String[] args) throws Exception{
int cases = Integer.parseInt(reader.readLine());
String data;
reader.readLine();
while(cases-- != 0) {
mapping = new TreeMap<>(); total = 0;
while((data = reader.readLine()) != null && !data.equals("")) {
total++;
mapping.compute(data, (k, v) -> v == null ? 1: ++v);
}
process();
if(cases != 0)
writer.newLine();
}
writer.close();
reader.close();
}
static void process() throws Exception{
for(String species: mapping.navigableKeySet()) {
writer.write(String.format("%s %.4f\n", species, (double)mapping.get(species)/total * 100));
}
}
}