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. CCF 模拟E DFS深搜

    http://115.28.138.223:81/view.page?opid=5 这道题问的很怪. 起点DFS,每一个点还要DFS一次,统计不能到终点的个数 数据量不大这样做也能AC #includ ...

  2. Qt5 程序启动画面图片效果

    2333每次打开photoshop开启画面是在酷炫,其实也不难啦. 新建项目名称SplashScreen,基类默认,取消创建界面复选框,完成. 代码如下,图片资源文件自己添加(已上传还未实现动态效果学 ...

  3. Spring+SpringMVC+MyBatis+Maven 服务端XML配置

    项目目录结构 spring-mybatis.xml <?xml version="1.0" encoding="UTF-8"?> <beans ...

  4. easyui只打开一个tab

    下面是JS代码: var curr = null; //curr为当前tab的标题,在else中赋值 function addtab(href, tabtitle) { if (curr) { $(' ...

  5. 深度分析Linux下双网卡绑定七种模式 多网卡的7种bond模式原理

    http://blog.csdn.net/abc_ii/article/details/9991845多网卡的7种bond模式原理 Linux网卡绑定mode共有七种(~) bond0.bond1.b ...

  6. JavaScript工作原理和Node异步I/O

    1. 什么是JavaScript解析引擎? 简单地说,JavaScript解析引擎就是能够“读懂”JavaScript代码,并准确地给出代码运行结果的一段程序.比如var a=1+2:对于静态语言来说 ...

  7. c++数据类型和定义

    我们都知道,刚开始学习数学的时候.乘法口诀.99乘法口诀.这个是大家都需要背的.背熟了这个,大家才能知道遇到算术题如何计算.这个99乘法口诀就是一种定义. 同样任何的语言都会有很多的定义.比如语文:各 ...

  8. Linux下安装Flask开发框架

    Flask是开发pythonweb的一个轻量级框架,适合初学者使用,当有了熟练的web基础后,再继续学习高级框架的开发,Linux一般安装好之后都会有python开发环境,给开发带来方便,下面是Fla ...

  9. delphi的取整函数round、trunc、ceil和floor

    delphi的取整函数round.trunc.ceil和floor 首先引入math单元 uses math; 1.Round(四舍六入五留双) 功能说明:对一个实数进行四舍五入.(按照银行家算法) ...

  10. linux (RHEL) 添加和删除用户

    linux添加新用户使用 useradd -----create a new user or update default new user information 删除用户使用userdel  -- ...