2019独角兽企业重金招聘Python工程师标准>>>

487-3279

Time Limit: 2000MS Memory Limit: 65536K

Total Submissions: 242236 Accepted: 42954

Description

Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or phrase. For example, you can call the University of Waterloo by dialing the memorable TUT-GLOP. Sometimes only part of the number is used to spell a word. When you get back to your hotel tonight you can order a pizza from Gino's by dialing 310-GINO. Another way to make a telephone number memorable is to group the digits in a memorable way. You could order your pizza from Pizza Hut by calling their ``three tens'' number 3-10-10-10.

The standard form of a telephone number is seven decimal digits with a hyphen between the third and fourth digits (e.g. 888-1200). The keypad of a phone supplies the mapping of letters to numbers, as follows:

A, B, and C map to 2

D, E, and F map to 3

G, H, and I map to 4

J, K, and L map to 5

M, N, and O map to 6

P, R, and S map to 7

T, U, and V map to 8

W, X, and Y map to 9

There is no mapping for Q or Z. Hyphens are not dialed, and can be added and removed as necessary. The standard form of TUT-GLOP is 888-4567, the standard form of 310-GINO is 310-4466, and the standard form of 3-10-10-10 is 310-1010.

Two telephone numbers are equivalent if they have the same standard form. (They dial the same number.)

Your company is compiling a directory of telephone numbers from local businesses. As part of the quality control process you want to check that no two (or more) businesses in the directory have the same telephone number.

Input

The input will consist of one case. The first line of the input specifies the number of telephone numbers in the directory (up to 100,000) as a positive integer alone on the line. The remaining lines list the telephone numbers in the directory, with each number alone on a line. Each telephone number consists of a string composed of decimal digits, uppercase letters (excluding Q and Z) and hyphens. Exactly seven of the characters in the string will be digits or letters.

Output

Generate a line of output for each telephone number that appears more than once in any form. The line should give the telephone number in standard form, followed by a space, followed by the number of times the telephone number appears in the directory. Arrange the output lines by telephone number in ascending lexicographical order. If there are no duplicates in the input print the line:

No duplicates.

Sample Input

12

4873279

ITS-EASY

888-4567

3-10-10-10

888-GLOP

TUT-GLOP

967-11-11

310-GINO

F101010

888-1200

-4-8-7-3-2-7-9-

487-3279

Sample Output

310-1010 2

487-3279 4

888-4567 3

Source

East Central North America 1999

import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;public class Main {static char toDigit(char c){switch(c){case 'A':case 'B':case 'C':return '2';case 'D':case 'E':case 'F':return '3';case 'G':case 'H':case 'I':return '4';case 'J':case 'K':case 'L':return '5';case 'M':case 'N':case 'O':return '6';case 'P':case 'R':case 'S':return '7';case 'T':case 'U':case 'V':return '8';case 'W':case 'X':case 'Y':return '9';default:return c;}}//此方法使用字符字符数组,自己处理连字符,大小写等,通过了POJ在线测试static String format(char[] a){char[] re = new char[8];int index = 0;for(int i=0; i<a.length; ++i){if(a[i] != '-'){if(a[i] >= '1' && a[i] <= '9'){re[index++] = a[i];}else if(a[i] >= 'a' && a[i] <= 'b') {re[index++] = (char)(a[i] - 32);}else{re[index++] = toDigit(a[i]);}}}for(int i=6; i>=3; --i){re[i+1] = re[i];}re[3]= '-';return String.valueOf(re);}static boolean noDuplicates(Map<String, Integer> map){Iterator<String> it = map.keySet().iterator();while(it.hasNext()){String key = it.next();Integer value = map.get(key);if(value.intValue() != 1){return false;}}return true;}public static void main(String[] args) {Map<String,Integer> map = new HashMap<String,Integer>();Scanner in = new Scanner(new BufferedInputStream(System.in));int n = Integer.valueOf(in.nextLine());String phone = null;for(int i=0; i<n; ++i){phone = format(in.nextLine().toCharArray());if(map.containsKey(phone)){map.put(phone, map.get(phone) + 1);}else{map.put(phone, 1);}}in.close();if(noDuplicates(map)){System.out.println("No duplicates.");}else{Iterator<String> it = map.keySet().iterator();List<String> list = new ArrayList<String>();while(it.hasNext()){list.add(it.next());}Collections.sort(list);for(int i=0; i<list.size(); ++i){Integer value = map.get(list.get(i));if(value.intValue() != 1){System.out.println(list.get(i) + " " + value);}}}}
}
//使用此方法,由于太多字符串操作,导致在POJ上运行超出限定时间static String format(String input){input = input.replaceAll("-", "");input = input.toUpperCase();char[] arr = input.toCharArray();for(int i=0; i<arr.length; ++i){arr[i] = toDigit(arr[i]);}input = String.valueOf(arr);String result = input.substring(0, 3) + "-" + input.substring(3);return result;}

转载于:https://my.oschina.net/u/553266/blog/301373

POJ 1002 487-3279相关推荐

  1. 字符串专题:map POJ 1002

    第一次用到是在'校内赛总结'扫地那道题里面,大同小异 map<string,int>str 可以专用做做字符串的匹配之类的处理 string donser; str [donser]++ ...

  2. POJ 1002 解题分析

    Technorati 标签: ACM,POJ 题目描述 题目链接 POJ 1002 487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Sub ...

  3. 一个字典树问题--电话号码转化问题(POJ 1002 487-3279)

    字典树,又称为单词查找树,Trie树.是一种用于快速检索多叉树的结构.典型应用于统计,排序和保存大量字符串.利用字符串的前缀来减少存储空间,减少无谓的比较,提高查询效率. 字典树根节点不包含任何数据, ...

  4. POJ 1002题 解题报告

    这个是超时版的: #include<iostream> #include<string> using namespace std; typedef struct Telepho ...

  5. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

  6. ps安装程序检测到计算机重启过程,photoshop cs6安装过程中安装程序遇到错误:请重启计算机,解决办法...

    1.关闭防火墙和杀毒软件 2.删除注册表 依次展开HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager目录,找到其中的 ...

  7. ICPC训练联盟2021寒假冬令营(7)_2021.01.26_笔记

    文章目录 试题链接 学习笔记 - C++STL.贪心算法 C++STL 迭代器 STL算法 关联式容器 贪心算法 介绍 使用贪心法能否得到最优解,是必须加以证明的. 体验贪心法内涵的实验范例 贪心法的 ...

  8. 企业喜欢用容易被记住的电话号码(树解法)

    一个字典树有关问题-电话号码转化有关问题(POJ 1002 487-3279) 转自  http://www.myexception.cn/program/1264292.html 转自  http: ...

  9. D - Fliptile POJ - 3279(翻转问题)

    D - Fliptile POJ - 3279 题意: 给一个m*n的01矩阵,对某一块砖踩一脚,1->0 || 0->1, 求将整个举证全部变为0最少踩几次 典型的翻转问题,此类问题的特 ...

最新文章

  1. python 图像处理模块pillow
  2. DeepChem | DeepChem的图卷积特征化器
  3. 城市大脑不仅是AI系统,更是结合人类智慧的混合智能巨系统
  4. canvas动画特效 之 星空
  5. jstat和jmap使用
  6. springboot学习笔记(七)
  7. ITK:减去两个图像
  8. /usr/bin/ld: cannot find -lltdl collect2: ld returned 1 exit status make: *** [sapi/cgi/php-cgi] Err
  9. 数据源管理 | Kafka集群环境搭建,消息存储机制详解
  10. RedHat官方OpenShift Hands-on实验环境脚本
  11. centos7 菜鸟第一天--输入法在哪
  12. jQuery hover事件鼠标滑过图片半透明标题文字滑动显示隐藏
  13. python zfill_Python字符串zfill()
  14. Centos下tmux工具使用方法
  15. 天视通ipc地址修改工具_远程运行小工具PsExec
  16. atitit knowmng知识管理 索引part2
  17. 别再问我exe反编译成Python脚本了!
  18. 牛客刷题<17>用3-8译码器实现全减器
  19. Win11想运行老游戏怎么设置
  20. ios QQ下拉列表 UITableViewHeaderFooterView

热门文章

  1. pydev工程linux运行,Linux平台下Python的安装及IDE开发环境搭建
  2. 搜集侠采集织梦系统模板
  3. CSS 命名规范参考及书写注意事项
  4. viewState 与session[转]
  5. 最短路径——SPFA算法(蓝桥杯试题集)
  6. Linux(debian7)操作基础(十)之字符界面使用指南
  7. Qt Ctreator搭配VS2013调试——整合QML/C++调试需要的从属调试引擎无法被创建
  8. 【AI视野·今日Sound 声学论文速览 第一期】Thu, 14 Apr 2022
  9. 【ffmpeg】基本使用方法总结
  10. 【今日CS 视觉论文速览】10 Jan 2019