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 |
Re:找不到测试数据的同学们看过来了。In Reply To:找不到测试数据的同学们看过来了。 Posted by:wbbcbbt at 2013-02-21 18:01:08 不错这个数据很有帮助,贴一下我的ac代码: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // long start = System.currentTimeMillis(); int n = Integer.parseInt(br.readLine()); HashMap<String, Integer> count = new HashMap<String, Integer>(n); for (int i = 0; i < n; i++) { char[] s = br.readLine().toCharArray(); StringBuilder sb = new StringBuilder(); for (int j = 0; j < s.length; j++) { if (s[j] == '-') { continue; } switch (s[j]) { case 'A': case 'B': case 'C': sb.append('2'); break; case 'D': case 'E': case 'F': sb.append('3'); break; case 'G': case 'H': case 'I': sb.append('4'); break; case 'J': case 'K': case 'L': sb.append('5'); break; case 'M': case 'N': case 'O': sb.append('6'); break; case 'P': case 'R': case 'S': sb.append('7'); break; case 'T': case 'U': case 'V': sb.append('8'); break; case 'W': case 'X': case 'Y': sb.append('9'); break; default: sb.append(s[j]); break; } } String ss = sb.toString(); if (count.containsKey(ss)) { count.put(ss, count.get(ss) + 1); } else { count.put(ss, 1); } } // long end = System.currentTimeMillis(); // System.out.println(end - start); ArrayList<String> res = new ArrayList<String>(); for (String key : count.keySet()) { if (count.get(key) > 1) { res.add(key); } } if (res.isEmpty()) { System.out.println("No duplicates."); return; } // System.out.println(System.currentTimeMillis() - start); Collections.sort(res); for (String s : res) { System.out.println(s.substring(0, 3) + "-" + s.substring(3) + " " + count.get(s)); } // System.out.println(System.currentTimeMillis() - start); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator