poj 2418(TreeMap)

题意:对给定的一些树名进行字典排序并输出所占的比例


import java.util.*;
import java.util.Map.Entry;

public class Main {

	Scanner sc=new Scanner(System.in);
	void init(){
		int sum=0;
		TreeMap<String, Integer> tree=new TreeMap<String, Integer>();
		while(sc.hasNext()){
			String s=sc.nextLine();
			sum+=1;
			if(tree.containsKey(s))
				tree.put(s, tree.get(s)+1);
			else
				tree.put(s, 1);
		}
		for(Entry<String, Integer> set:tree.entrySet()){
			System.out.printf( "%s %.4f\n",set.getKey(),(double)tree.get(set.getKey())*100.0/sum);
		}
	}
	public static void main(String[] args) throws Exception {
		new Main().init();
	}
}


你可能感兴趣的:(exception,String,tree,Integer,Class,import)