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 |
P1002,为什么会出现Runtime Error,请高手指教,附JAVA源代码import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Scanner; import java.util.Vector; public class Main { final String fileName = "A-small-practice"; public void solve() throws IOException { // Scanner sc = new Scanner(new File(fileName + ".in")); Scanner sc = new Scanner(System.in); int T = sc.nextInt(); String line; String code; int len; HashMap hm = new HashMap(); char c; String vv; Integer cc; int cnt; HashMap<String, String> table = new HashMap<String, String>(); int v; for (int i = 0; i < 3; i++) { v = 2; table.put("" + (char) ('A' + i), "" + v); v++; table.put("" + (char) ('D' + i), "" + v); v++; table.put("" + (char) ('G' + i), "" + v); v++; table.put("" + (char) ('J' + i), "" + v); v++; table.put("" + (char) ('M' + i), "" + v); v++; table.put("" + (char) ('P' + i), "" + v); v++; table.put("" + (char) ('T' + i), "" + v); v++; table.put("" + (char) ('W' + i), "" + v); } table.put("S", "7"); Vector vec = new Vector(); for (int t = 0; t < T; t++) { line = sc.next(); len = line.length(); code = ""; cnt = 0; for (int i = 0; i < len; i++) { c = line.charAt(i); if (c != '-') { if (c < '0' || c > '9') { vv = (String) table.get("" + c); } else { vv = "" + c; } code += vv; cnt++; if (cnt == 3) { code += '-'; } } } cc = (Integer) hm.get(code); if (cc == null) { hm.put(code, 1); } else { hm.put(code, cc + 1); } // System.out.println(line + "-->" + code); } for (Iterator it = hm.keySet().iterator(); it.hasNext();) { code = (String) it.next(); cc = (Integer) hm.get(code); if (cc > 1) { vec.addElement(code + " " + cc); // System.out.println(code+" "+cc); } } int size = vec.size(); if (size == 0) { System.out.println("No duplicates."); } else { Collections.sort(vec.subList(0, vec.size())); for (Iterator it = vec.iterator(); it.hasNext();) { code = (String) it.next(); System.out.println(code); } } sc.close(); } public static void main(String[] args) { try { new Main().solve(); } catch (IOException ex) { ex.printStackTrace(); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator