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

大虾求救。。。总是Runtime Error...

Posted by dingo at 2007-02-28 03:52:52 on Problem 1002
import java.io.*;
import java.util.*;


public class Main {
	public static void main(String args[]) throws Exception {
		BufferedReader stdin = new BufferedReader(new InputStreamReader(
				System.in));
		HashMap<Integer, Integer> dicMap = new HashMap<Integer, Integer>();
		String line;
		while (!(line = stdin.readLine()).equals("")) {
			StringTokenizer st = new StringTokenizer(line);
			String in = st.nextToken();
			in = tras(in);
			if (in.length() == 7) {
				int tmp = Integer.parseInt(in);
				if (dicMap.containsKey(tmp)) {
					int cnt = dicMap.get(tmp).intValue();
					dicMap.put(tmp, ++cnt);
				} else {
					dicMap.put(tmp, 1);
				}
			}
		}
		Set keySet = dicMap.keySet();
		Integer[] keyInteger = new Integer[dicMap.size()];
		for (int i = 0; i < keyInteger.length; i++) {
			keyInteger[i] = (Integer) keySet.toArray()[i];
		}
		Arrays.sort(keyInteger);
		for (int i = 0; i < keyInteger.length; i++) {
			int n = dicMap.get(keyInteger[i]);
			if (n > 1) {
				System.out.printf("%s-%s %s\n", Integer.toString(keyInteger[i])
						.substring(0, 3), Integer.toString(keyInteger[i])
						.substring(3, 7), n);
			} else if (n == 1) {
				System.out.printf("%s-%s No duplicates.\n", Integer.toString(
						keyInteger[i]).substring(0, 3), Integer.toString(
						keyInteger[i]).substring(3, 7));
			}
		}
	}

	public static String tras(String in) {
		in = in.replace("-", "");
		char[] tmp = in.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			switch (tmp[i]) {
			case 'a':
				tmp[i] = '2';
				break;
			case 'A':
				tmp[i] = '2';
				break;
			case 'b':
				tmp[i] = '2';
				break;
			case 'B':
				tmp[i] = '2';
				break;
			case 'c':
				tmp[i] = '2';
				break;
			case 'C':
				tmp[i] = '2';
				break;
			case 'd':
				tmp[i] = '3';
				break;
			case 'D':
				tmp[i] = '3';
				break;
			case 'e':
				tmp[i] = '3';
				break;
			case 'E':
				tmp[i] = '3';
				break;
			case 'f':
				tmp[i] = '3';
				break;
			case 'F':
				tmp[i] = '3';
				break;
			case 'g':
				tmp[i] = '4';
				break;
			case 'G':
				tmp[i] = '4';
				break;
			case 'h':
				tmp[i] = '4';
				break;
			case 'H':
				tmp[i] = '4';
				break;
			case 'i':
				tmp[i] = '4';
				break;
			case 'I':
				tmp[i] = '4';
				break;
			case 'j':
				tmp[i] = '5';
				break;
			case 'J':
				tmp[i] = '5';
				break;
			case 'k':
				tmp[i] = '5';
				break;
			case 'K':
				tmp[i] = '5';
				break;
			case 'l':
				tmp[i] = '5';
				break;
			case 'L':
				tmp[i] = '5';
				break;
			case 'm':
				tmp[i] = '6';
				break;
			case 'M':
				tmp[i] = '6';
				break;
			case 'n':
				tmp[i] = '6';
				break;
			case 'N':
				tmp[i] = '6';
				break;
			case 'o':
				tmp[i] = '6';
				break;
			case 'O':
				tmp[i] = '6';
				break;
			case 'p':
				tmp[i] = '7';
				break;
			case 'P':
				tmp[i] = '7';
				break;
			case 'r':
				tmp[i] = '7';
				break;
			case 'R':
				tmp[i] = '7';
				break;
			case 's':
				tmp[i] = '7';
				break;
			case 'S':
				tmp[i] = '7';
				break;
			case 't':
				tmp[i] = '8';
				break;
			case 'T':
				tmp[i] = '8';
				break;
			case 'u':
				tmp[i] = '8';
				break;
			case 'U':
				tmp[i] = '8';
				break;
			case 'v':
				tmp[i] = '8';
				break;
			case 'V':
				tmp[i] = '8';
				break;
			case 'w':
				tmp[i] = '9';
				break;
			case 'W':
				tmp[i] = '9';
				break;
			case 'x':
				tmp[i] = '9';
				break;
			case 'X':
				tmp[i] = '9';
				break;
			case 'y':
				tmp[i] = '9';
				break;
			case 'Y':
				tmp[i] = '9';
				break;
			default:
				break;
			}
		}
		return new String(tmp);
	}
}

曾经尝试自己写Qsort和冒泡,还是RE,也把自己写的检查内容部分改过,现在用HashMap,但是还是RE...

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