首页 > 代码库 > 算法:号码转换问题
算法:号码转换问题
该题太水,没必要参考。
package practice;import java.io.BufferedInputStream;import java.util.Map;import java.util.Scanner;import java.util.TreeMap;/** * @author caiyu * @date 2014-11-2 */public class MemorableTelNumber { public static void main(String[] args) { Scanner cin = new Scanner(new BufferedInputStream(System.in)); int l = cin.nextInt(); String num; Map<String, Integer> m = new TreeMap<String, Integer>(); StringBuffer c; int tmp; String s; for (int i = 0; i < l; i++) { num = cin.next().trim(); c = new StringBuffer(); for (int j = 0, len = num.length(); j < len; j++) { tmp = handle(num.charAt(j)); if (0 <= tmp && tmp <= 9) c.append(tmp); } if (c.length() == 7) { c.insert(3, "-"); s = c.toString(); if (m.containsKey(s)) m.put(s, m.get(s) + 1); else m.put(s, 1); } } for (String k : m.keySet()) { if (m.get(k) > 1) System.out.println(k + " " + m.get(k)); } } private static int handle(char c) { if (c == ‘A‘ || c == ‘B‘ || c == ‘C‘) return 2; if (c == ‘D‘ || c == ‘E‘ || c == ‘F‘) return 3; if (c == ‘G‘ || c == ‘H‘ || c == ‘I‘) return 4; if (c == ‘J‘ || c == ‘K‘ || c == ‘L‘) return 5; if (c == ‘M‘ || c == ‘N‘ || c == ‘O‘) return 6; if (c == ‘P‘ || c == ‘R‘ || c == ‘S‘) return 7; if (c == ‘T‘ || c == ‘U‘ || c == ‘V‘) return 8; if (c == ‘W‘ || c == ‘X‘ || c == ‘Y‘) return 9; if (c == ‘-‘) return -1; return Integer.parseInt("" + c); }}
算法:号码转换问题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。