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

现在是超时啊!!!

Posted by dailyye at 2008-04-11 22:13:27 on Problem 1002
In Reply To:一直是runtime error Posted by:dailyye at 2008-04-11 21:35:18
import java.util.Arrays;
import java.util.Comparator;
import java.util.Hashtable;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class P1002 {

	/**
	 * @param args
	 */

	public static void main(String[] args)throws NumberFormatException { 
		long start=System.currentTimeMillis();
		Scanner cin = new Scanner(System.in);
		int n = cin.nextInt();
		int num[]=new int[10000000];
		if(n>100000)n=100000;
		for (int i = 0; i < n; i++) {
			String sNumber = cin.next();
			sNumber = sNumber.replace("A", "2");
			sNumber = sNumber.replace("B", "2");
			sNumber = sNumber.replace("C", "2");
			sNumber = sNumber.replace("D", "3");
			sNumber = sNumber.replace("E", "3");
			sNumber = sNumber.replace("F", "3");
			sNumber = sNumber.replace("G", "4");
			sNumber = sNumber.replace("H", "4");
			sNumber = sNumber.replace("I", "4");
			sNumber = sNumber.replace("J", "5");
			sNumber = sNumber.replace("K", "5");
			sNumber = sNumber.replace("L", "5");
			sNumber = sNumber.replace("M", "6");
			sNumber = sNumber.replace("N", "6");
			sNumber = sNumber.replace("O", "6");
			sNumber = sNumber.replace("P", "7");
			sNumber = sNumber.replace("R", "7");
			sNumber = sNumber.replace("S", "7");
			sNumber = sNumber.replace("T", "8");
			sNumber = sNumber.replace("U", "8");
			sNumber = sNumber.replace("V", "8");
			sNumber = sNumber.replace("W", "9");
			sNumber = sNumber.replace("X", "9");
			sNumber = sNumber.replace("Y", "9");
			sNumber = sNumber.replace("-", "");
			
			 
				try {
				int iNumber = Integer.parseInt(sNumber);
				//System.out.println(iNumber);
				num[iNumber]++;
			} catch (Exception e) {
			}
			 
		}
		int temp=0;
		for(int i=0;i<num.length;i++)
			
		{
			if(num[i]>1)
			{
				String s=new Integer(i).toString();
				 int tempo=0;
				for(int j=0;j<7-s.length();j++)
				{ 
					tempo++;
						System.out.print("0"); 
						if(tempo==3)
							System.out.print("-"); 
				}
				for(int m=0;m<s.length();m++)
				{
					
					tempo++;
					System.out.print(s.charAt(m));
					if(tempo==3)
						System.out.print("-"); 
				}
				System.out.println(" "+num[i]);
				
				temp=1;
			}
			
		}
		if(temp==0) 
		{
			System.out.println("No duplicates.");
		}
		long end=System.currentTimeMillis();
		System.out.println(end-start);
	}
}
 

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