487-3279
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 236746   Accepted: 41288

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

 
 
  水题,提高题
 
  当时做的时候这道题WA了好多次,原因就是以下注意里面写的情况没有考虑到。这道题没有什么算法,但是考验基本功,可以作为算法入门的提高题来练习。另外这道题有很多种优化方法(据说可以用hash??),看Status中各位大神提交的代码速度就可以知道。我这个600+MS的简直就是渣渣……抽空优化下。参考优化链接:POJ1002-487-3279
 
  题意:给你n个格式不同电话号码,你需要统计出其中出现了一次以上的电话号码的次数,并按字典序输出。如果没有号码出现了一次以上,则输出"No duplicates."。
 
  思路:首先写好输入框架,然后把映射函数写出来,最后就是统计次数了。你可以把每一个电话号码转换成一个整数,然后用一个数组记录它出现的次数,数组的下标代表电话号码,对应的数组的值代表出现的次数。这样输出的时候从头到尾遍历一遍找出次数>1的号码输出即可。
  这样做的优点是不用排序,缺点是速度慢(因为号码有7位,所以数组开到了1e7,从头到尾遍历一遍很慢)。
 
  注意
  1.输出的时候注意输出前导0,printf("%03d-%04d %d\n",i/10000,i%10000,a[i]);
  2.别忘了处理"No duplicates."的情况。
  3.用cin,cout的形式可能会超时。
 
  代码
 #include <iostream>
#include <stdio.h>
using namespace std;
#define MAXN 10000000
int a[MAXN+]={};
int Map(char c) //映射关系
{
if(''<=c && c<='')
return c-'';
else if(c=='A' || c=='B' || c=='C')
return ;
else if(c=='D' || c=='E' || c=='F')
return ;
else if(c=='G' || c=='H' || c=='I')
return ;
else if(c=='J' || c=='K' || c=='L')
return ;
else if(c=='M' || c=='N' || c=='O')
return ;
else if(c=='P' || c=='R' || c=='S')
return ;
else if(c=='T' || c=='U' || c=='V')
return ;
else if(c=='W' || c=='X' || c=='Y')
return ;
else
return -;
}
int main()
{
char s[],c;
int i,j,n;
scanf("%d%c",&n,&c);
for(i=;i<=n;i++){ //输入n个数
scanf("%s",s);
int tel = ;
for(j=;s[j];j++){
int t = Map(s[j]);
if(t==-) continue;
tel = tel*+t;
}
a[tel]++; //次数加1
}
int f=false; //有无重复
for(i=;i<MAXN;i++) //输出
if(a[i]>){
f=true;
printf("%03d-%04d %d\n",i/,i%,a[i]);
}
if(!f) cout<<"No duplicates."<<endl;
return ;
}

Freecode : www.cnblogs.com/yym2013

poj 1002:487-3279(水题,提高题 / hash)的更多相关文章

  1. poj 2236:Wireless Network(并查集,提高题)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 16065   Accepted: 677 ...

  2. poj 3321:Apple Tree(树状数组,提高题)

    Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18623   Accepted: 5629 Descr ...

  3. POJ 1488 Tex Quotes --- 水题

    POJ 1488 题目大意:给定一篇文章,将它的左引号转成 ``(1的左边),右引号转成 ''(两个 ' ) 解题思路:水题,设置一个bool变量标记是左引号还是右引号即可 /* POJ 1488 T ...

  4. C基础的练习集及测试答案(提高题)

    提高题:1.编写程序,随机生成一个1~10内的数,让对方猜3次.如果3次内能猜中则输出“恭喜你”:若3次内猜不中则输出正确答案.C语言中提供生成随机数的函数rand()用法:①所需头文件:#inclu ...

  5. [POJ 1002] 487-3279 C++解题报告

        487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 228365   Accepted: 39826 D ...

  6. POJ 3627 Bookshelf 贪心 水~

    最近学业上堕落成渣了.得开始好好学习了. 还有呀,相家了,好久没回去啦~ 还有和那谁谁谁... 嗯,不能发表悲观言论.说好的. 如果这么点坎坷都过不去的话,那么这情感也太脆弱. ----------- ...

  7. 字符串专题:map POJ 1002

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

  8. POJ 1002 487-3279

    A - 487-3279 Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  9. Educational Codeforces Round 12补题 经典题 再次爆零

    发生了好多事情 再加上昨晚教育场的爆零 ..真的烦 题目链接 A题经典题 这个题我一开始推公式wa 其实一看到数据范围 就算遍历也OK 存在的问题进制错误 .. 思路不清晰 两个线段有交叉 并不是端点 ...

随机推荐

  1. 修改vb程序图标

    1. 2.

  2. NDK学习二: NDK目录结构

    NDK目录结构   NDK下载好之后目录结构如下:         目录名 描述 build   存放和编译相关的脚本文件,最外面的ndk-build就是调用该目录下的makefile文件,其中mak ...

  3. Javascript闭包——懂不懂由你,反正我是懂了

    摘要:“如果你不能向一个六岁的孩子解释清楚,那么其实你自己根本就没弄懂.”好吧,我试着向一个27岁的朋友就是JS闭包(JavaScript closure)却彻底失败了. 越来越觉得国内没有教书育人的 ...

  4. VirtualBox中安装Ubuntu12.04/Ubuntu14.04虚拟机

    NOTE: 一开始安装的Ubuntu12.04,后来又重新安装了14.04.截图基本使用了安装12.04时的截图,后来安装14.04时又补充了几张.该安装过程对Ubuntu12.04和14.04都是适 ...

  5. emmet 太 hackble 了 。。。

    http://www.open-open.com/lib/view/open1451954899292.html

  6. bbs/贴吧/盖楼的技术实现(PHP)

    2015年3月5日 14:36:44 更新: 2015年7月18日 16:33:23 星期六 目标, 实现类似网易盖楼的功能, 但是不重复显示帖子 效果: * 回复 //1楼 ** 回复 //1楼的子 ...

  7. 24. javacript高级程序设计-最佳实践

    1. 最佳实践 l 来自其他语言的代码约定可以用于决定何时进行注释,以及如何进行缩进,不过JavaScript需要针对其松散类型的性质创造一些特殊的约定 l javascript应该定义行为,html ...

  8. effective OC2.0 52阅读笔记(二 对象、消息、运行期)

    第二章:对象.消息.运行期 6 理解属性这一概念 总结:OC解决硬编码偏移量问题的做法,一种方案是把实例变量当做一种存储偏移量所用的特殊变量,交由类对象保管,偏移量会在运行期查找,叫做稳固的“应用程序 ...

  9. python中的编码问题:以ascii和unicode为主线

      1.unicode.gbk.gb2312.utf-8的关系 http://www.pythonclub.org/python-basic/encode-detail 这篇文章写的比较好,utf-8 ...

  10. codeforces 500B.New Year Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...