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

what is wrong with this code??

Posted by gnamusg at 2008-07-26 12:55:57 on Problem 1002
HI guys,
the following code is working in my pc but somehow the online judge has gone crazy.. can anyone find something wrong with this??


import java.util.*;
public class Main {
		public static void main(String[] args){
			
			Scanner in = new Scanner(System.in);
			
			Integer arraySize = new Integer(Integer.valueOf(in.nextLine()));
			
			int[] telNumbers = new int[arraySize];

			
			for(int i = 0; i<arraySize ; i++){
				StringBuilder formatedNumber = new StringBuilder("");
				String temp = in.nextLine().replaceAll("-", "");
				
				
				for(int j = 0; j<temp.length(); j++){				
						formatedNumber.append(returnEqui(temp.charAt(j)));					
				}
				
				telNumbers[i]= Integer.parseInt(formatedNumber.toString());
			}
			int counter;
			Arrays.sort(telNumbers);
			int noOfDuplicates=0;
			
			for(int i = 0; i < arraySize-1 ; i++){
				counter = 1;
				
				for(int j = i+1; j<arraySize; j++){
					if(telNumbers[i]==(telNumbers[j])){
						counter++;			
						i++;
					}
				}
				
				if(counter>1){
					noOfDuplicates++;
					System.out.println((telNumbers[i]/10000) + "-" + (telNumbers[i]%10000) + " " +counter);
				}
			
				
			}
			if(noOfDuplicates == 0){
				System.out.println("No duplicates");
			}
			
			
				
			
		}
		public static char returnEqui(char letter){
			switch(letter){
			case 'A': 
			case 'B': 
			case 'C':
				return '2';
				
			case 'D':
			case 'E':
			case 'F':
				return '3';
			case 'G':
			case 'H':
			case 'I':
				return '4';
				
			case 'J':
			case 'K':
			case 'L':
				return '5';
			case 'M':
			case 'N':
			case 'O':
				return '6';
			case 'P':
			case 'R':
			case 'S':
				return '7';
			case 'T':
			case 'U':
			case 'V': 
				return '8';
			case 'W': 
			case 'X':
			case 'Y':
				return '9';
				
			default:
				return letter;
			}
		}
}

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