Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

How to use iterator in Java1.5?

Posted by niktop at 2013-09-13 11:46:58 on Problem 2418
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator