Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
How to use iterator in Java1.5?My code for the problem 2418 is: import java.io.*; import java.math.*; import java.util.*; import java.lang.*; import java.security.SecureRandom; import java.math.BigInteger; class Main{ public static void main(String[] args)throws java.lang.Exception{ Scanner cin = new Scanner(System.in); TreeMap<String, Integer> map = new TreeMap<String, Integer>(); int trees = 0; while(true){ String tree = cin.nextLine(); if(tree==null){ break; } if(tree.length()==0)break; trees++; if(map.containsKey(tree)){ map.put(tree, map.get(tree)+1); }else{ map.put(tree, 1); } } Iterator<String> itr = map.keySet().iterator(); while(itr.hasNext()){ String tree = itr.next(); System.out.print(tree + " " ); double percent = (double)map.get(tree)/trees*100; System.out.format("%.4f\n", percent); } } } The code is running fine on my machine but it gives runtime error on the poj system. What may be the problem? Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator