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

哪位同学给看下这段代码有什么问题(java),Wrong Answer

Posted by feixue300 at 2018-02-27 15:51:11 on Problem 1007 and last updated at 2018-02-27 15:52:25
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	@SuppressWarnings("resource")
	public static void main(String args[]) throws Exception {
		Map<String, Integer> ret = new TreeMap<String, Integer>();
		Scanner cin = new Scanner(System.in);
		int inputLength = cin.nextInt();
		int inputCount = cin.nextInt();
		
		for (int i = 1; i <= inputCount; i++) {
			int val = 0;
			String _line = cin.next();
			char[] line = _line.toCharArray();
			
			for (int j = 0; j < inputLength - 1; j++) {
				for (int k = j + 1; k < inputLength; k++) {
					if (line[j] > line[k])
						val++;
				}
			}
			ret.put(_line, val * 1000 + i);// 使val相同时先进的排在前面
		}
		
		// 升序比较器
		Comparator<Map.Entry<String, Integer>> valueComparator = new Comparator<Map.Entry<String, Integer>>() {
			public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
				return o1.getValue() - o2.getValue();
			}
		};
		// map转换成list进行排序
		List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(ret.entrySet());
		// 排序
		Collections.sort(list, valueComparator);
		
		for (Map.Entry<String, Integer> entry : list) {
			System.out.println(entry.getKey());
		}
	}
}

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