package com_1;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.TreeMap;
import java.util.TreeSet;
public class Shuru2
{
public static void main(String [] args) throws IOException {
BufferedReader br=new BufferedReader(new FileReader("F:\\eclipse-workspace\\com_1\\src\\1.txt"));
TreeMap<Character,Integer> hm=new TreeMap<>();
int bb;
while((bb=br.read())!=-1) {
if((bb>='A'&&bb<='Z')||(bb>'a'&&bb<='z')) {
hm.put((char)bb,hm.containsKey((char)bb)?hm.get((char)bb)+1:1);
} }
br.close();
int max=0;
int sum=0;
int t=0;
for(Character k: hm.keySet()) {
sum=sum+hm.get(k);
}
TreeSet<Character> ts=new TreeSet<>(new Comparator<Character>()
{
public int compare(Character a,Character b) {
int num=hm.get(a)-hm.get(b);
return num==0?1:(-num);
}
});
for(Character k: hm.keySet()) {
ts.add(k);
}
DecimalFormat df = new DecimalFormat("0.00%");
for (Character c : ts)
{
float bai=(float)hm.get(c)/sum; System.out.println(c+" "+hm.get(c)+" "+df.format(bai));
} //System.out.println(sum);
}}
整个人都不好了