Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
哪位同学给看下这段代码有什么问题(java),Wrong Answerimport 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator