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 blackboycqu at 2014-09-16 00:57:26 on Problem 1002
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		String[] strList = new String[n];
		for (int i = 0; i < n; i++) {
			strList[i] = covert(input.next());
		}

		Arrays.sort(strList);
		print(strList);
	}

	public static String covert(String str) {
		String list = "2223334445556667-77888999-";
		String getStr = "";
		for (int i = 0; i < str.length(); i++) {
			if (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z') {
				getStr = getStr + list.charAt(str.charAt(i) - 'A');
			} else if (str.charAt(i) != '-') {
				getStr = getStr + str.charAt(i);
			}
			if (getStr.length() == 3) {
				getStr = getStr + "-";
			}
		}
		return getStr;
	}

	public static void print(String[] str) {
		int count = 1;
		List l = new ArrayList();

		for (int i = 0; i < str.length - 1; i++) {
			if (str[i].equals(str[i + 1])) {
				count++;
			} else {
				if (count != 1) {
					str[i] = str[i] + " " + count;
					l.add(str[i]);
				}
				count = 1;
			}
		}

		for (int j = 0; j < l.size(); j++) {
			System.out.println(l.toArray()[j]);
		}

		if (l.isEmpty()) {
			System.out.println("No duplicates.");
		}
	}
}

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