Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: POJ 1002: The code is not accepted by the system of online judge

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default POJ 1002: The code is not accepted by the system of online judge

    I am dealing with POJ 1002 which is a question of online judge from PKU. I test my program and all the cases pass. However, wrong answer is given by the system. I don't know what's wrong with my code. May anyone help me?

    The followings are contents of the question:

    487-3279
    Time Limit: 2000MS Memory Limit: 65536K
    Total Submissions: 214622 Accepted: 37411
    Description

    Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or phrase. For example, you can call the University of Waterloo by dialing the memorable TUT-GLOP. Sometimes only part of the number is used to spell a word. When you get back to your hotel tonight you can order a pizza from Gino's by dialing 310-GINO. Another way to make a telephone number memorable is to group the digits in a memorable way. You could order your pizza from Pizza Hut by calling their ``three tens'' number 3-10-10-10.

    The standard form of a telephone number is seven decimal digits with a hyphen between the third and fourth digits (e.g. 888-1200). The keypad of a phone supplies the mapping of letters to numbers, as follows:

    A, B, and C map to 2
    D, E, and F map to 3
    G, H, and I map to 4
    J, K, and L map to 5
    M, N, and O map to 6
    P, R, and S map to 7
    T, U, and V map to 8
    W, X, and Y map to 9

    There is no mapping for Q or Z. Hyphens are not dialed, and can be added and removed as necessary. The standard form of TUT-GLOP is 888-4567, the standard form of 310-GINO is 310-4466, and the standard form of 3-10-10-10 is 310-1010.

    Two telephone numbers are equivalent if they have the same standard form. (They dial the same number.)

    Your company is compiling a directory of telephone numbers from local businesses. As part of the quality control process you want to check that no two (or more) businesses in the directory have the same telephone number.

    Input

    The input will consist of one case. The first line of the input specifies the number of telephone numbers in the directory (up to 100,000) as a positive integer alone on the line. The remaining lines list the telephone numbers in the directory, with each number alone on a line. Each telephone number consists of a string composed of decimal digits, uppercase letters (excluding Q and Z) and hyphens. Exactly seven of the characters in the string will be digits or letters.
    Output

    Generate a line of output for each telephone number that appears more than once in any form. The line should give the telephone number in standard form, followed by a space, followed by the number of times the telephone number appears in the directory. Arrange the output lines by telephone number in ascending lexicographical order. If there are no duplicates in the input print the line:

    No duplicates.
    Sample Input

    12
    4873279
    ITS-EASY
    888-4567
    3-10-10-10
    888-GLOP
    TUT-GLOP
    967-11-11
    310-GINO
    F101010
    888-1200
    -4-8-7-3-2-7-9-
    487-3279
    Sample Output

    310-1010 2
    487-3279 4
    888-4567 3

    The following is my code:

    import java.util.Scanner;
    import java.util.ArrayList;
     
    public class Main {
    	public static void main(String[] args) {
    		Scanner input = new Scanner(System.in);
    		int n;
    		ArrayList<Integer> telelist = new ArrayList<Integer>();
     
    		n = input.nextInt();
     
    		for (int i = 0; i < n; i++){
    			char[] c;
    			c = input.next().replaceAll("-", "").toCharArray();
    			for (int j = 0; j < 7; j++) {
    				c[j] = transform(c[j]);
    			}
    			telelist.add(Integer.parseInt(new String(c)));
    		}
     
    		quicksort(telelist);
    		display(telelist);
     
    	}
     
    	public static char transform(char c) {
    		if (!(c >= 65 && c <= 89))
    			return c;
    		 char temp = c;
    		 switch(c) {
    		 case 'A': case 'B': case 'C':
    			 temp = '2';
    			 break;
    		 case 'D': case 'E': case 'F':
    			 temp = '3';
    			 break;
    		 case 'G': case'H': case 'I':
    			 temp = '4';
    			 break;
    		 case 'J': case 'K': case 'L':
    			 temp = '5';
    			 break;
    		 case 'M': case 'N': case 'O':
    			 temp = '6';
    			 break;
    		 case 'P': case 'R': case 'S':
    			 temp = '7';
    			 break;
    		 case 'T': case 'U': case 'V':
    			 temp = '8';
    			 break;
    		 case 'W': case 'X': case 'Y':
    			 temp = '9';
    			 break;
    		 }
    		 return temp;
    	}
     
    	public static void quicksort(ArrayList<Integer> list) {
    		quicksort(list, 0, list.size() - 1);
    	}
     
    	public static void quicksort(ArrayList<Integer> list, int head, int tail) {
    		if (tail > head) {
    			int pivot = partition(list, head, tail);
    			quicksort(list, head, pivot - 1);
    			quicksort(list, pivot + 1, tail);
    		}
    	}
     
    	public static int partition(ArrayList<Integer> list, int head, int tail) {
    		int low = head + 1;
    		int high = tail;
    		int pivot = list.get(head);
     
    		while (high > low) {
    			while (low <= high && list.get(low) <= pivot)
    				low++;
     
    			while (low <= high && list.get(high) > pivot)
    				high--;
     
    			if(high > low) {
    				int temp = list.get(high);
    				list.set(high, list.get(low));
    				list.set(low, temp);
    			}
    		}
     
    		while (high > head && list.get(high) >= pivot)
    			high--;
     
    		if (pivot > list.get(high)) {
    			list.set(head, list.get(high));
    			list.set(high, pivot);
    			return high;
    		} else {
    			return head;
    		}
    	}
     
    	public static void display(ArrayList<Integer> list) {
    		int temp = list.get(0);
    		boolean duplicate = false;
    		int count = 1;
    		int exist = 0;
     
     
    		while (count < list.size()) {
    			if (temp == list.get(count)) {
    				exist = exist + 1;
    				duplicate = true;
     
    				if (count == list.size() - 1) {
    					System.out.format("%03d-%04d" + " " + (exist + 1) + "%n", temp/10000, temp%10000);
    				}
    			} else {
    				if (exist > 0) {
    					System.out.format("%03d-%04d" + " " + (exist + 1) + "%n", temp/10000, temp%10000);
    				}
    				exist = 0;
    				temp = list.get(count);
    			}
     
    			count++;
     
    		}
     
    		if (duplicate == false)
    			System.out.println("No duplicate.");
     
    	}
     
    }


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: POJ 1002: The code is not accepted by the system of online judge

    I see your instructions and your code but I do not see your question.
    What seems to be the trouble?

  3. #3
    Junior Member
    Join Date
    Jun 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: POJ 1002: The code is not accepted by the system of online judge

    In fact, I send the code to the system and it will be tested. However, my code cannot pass the test of the system. It said my code cannot give the appropriate result.

Similar Threads

  1. Code for fetching harddisk id in all Operating System
    By Indrajeet in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 20th, 2013, 11:21 PM
  2. Smart Library Management System..What Wrong with my code
    By funkyonly4u in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 30th, 2012, 07:07 AM
  3. online system on java
    By u-khan1 in forum Paid Java Projects
    Replies: 0
    Last Post: March 8th, 2011, 06:02 AM