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

那位牛人帮忙看一下,为什么会有wrong answer.小弟初来乍到,还请多帮忙!万分感谢!

Posted by bixiaoting at 2011-03-12 14:49:17 on Problem 1002
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String sn = scan.nextLine();
		int n = Integer.parseInt(sn);
		List<String> arr = new ArrayList<String>();
		
		
		for(int i = 0;i < n; i ++) {
			String str = scan.nextLine();
			String w = "";
			for(int j = 0;j < str.length();j ++) {
				if(str.charAt(j) == 'W' || str.charAt(j) == 'X' || str.charAt(j) == 'Y') {
					str = str.substring(0,j).concat("9").concat(str.substring(j + 1));
				} else if(str.charAt(j) == 'A' || str.charAt(j) == 'B' || str.charAt(j) == 'C') {
					str = str.substring(0,j).concat("2").concat(str.substring(j + 1));
				} else if(str.charAt(j) == 'D' || str.charAt(j) == 'E' || str.charAt(j) == 'F') {
					str = str.substring(0,j).concat("3").concat(str.substring(j + 1));
				} else if(str.charAt(j) == 'G' || str.charAt(j) == 'H' || str.charAt(j) == 'I') {
					str = str.substring(0,j).concat("4").concat(str.substring(j + 1));
				} else if(str.charAt(j) == 'J' || str.charAt(j) == 'K' || str.charAt(j) == 'L') {
					str = str.substring(0,j).concat("5").concat(str.substring(j + 1));
				} else if(str.charAt(j) == 'M' || str.charAt(j) == 'N' || str.charAt(j) == 'O') {
					str = str.substring(0,j).concat("6").concat(str.substring(j + 1));
				} else if(str.charAt(j) == 'P' || str.charAt(j) == 'R' || str.charAt(j) == 'S') {
					str = str.substring(0,j).concat("7").concat(str.substring(j + 1));
				} else if(str.charAt(j) == 'T' || str.charAt(j) == 'U' || str.charAt(j) == 'V') {
					str = str.substring(0,j).concat("8").concat(str.substring(j + 1));
				} 
			}
			for(int j = 0;j < str.length();j ++) {
				if(str.charAt(j) == '-') {
					str = str.substring(0,j).concat(str.substring(j + 1));
				}
			}
			w = str.substring(0,3) + "-" + str.substring(3);
			arr.add(w);
		}
		
		for(int i = 0;i < arr.size();i ++) {
			int count = 0;
			boolean has = false;
			for(int j = i + 1;j < arr.size();j ++) {
				if(arr.get(i).equals(arr.get(j))) {
					arr.remove(j); 
					count ++;
					has = true;
				}
			}
			if(has) {
				arr.set(i, arr.get(i).concat(" ") + (1 + count));
			} else {
				arr.set(i, arr.get(i).concat(" No duplicates."));
			}
		}
		for(int i = 0;i < arr.size();i ++) {
			for(int j = i + 1;j < arr.size();j ++) {
				if(arr.get(i).compareTo(arr.get(j)) > 0) {
					String temp = arr.get(i);
					arr.set(i, arr.get(j));
					arr.set(j, temp);
				}
			}
		}
		for(int i = 0;i < arr.size();i ++) {
			System.out.println(arr.get(i));
		}
		
	}
}

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