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. mkdir:批量创建文件夹

    问题:mkdir dir[0-9]创建文件夹时,并没有如预期创建dir0~dir9这几个文件夹,而是创建了dir[0-9]这一个文件夹. 网上看了些相关资料,发现以前对[0-9]的理解不够透彻: &q ...

  2. VS中计算程序运行时间

    VS中计算程序运行的时间   http://bbs.csdn.net/topics/39068881 有时候在设计程序完了之后需要计算程序运行的时间. 这时候可以使用Windows的库函数 GetIi ...

  3. 【leetcode】Word Ladder

    Word Ladder Total Accepted: 24823 Total Submissions: 135014My Submissions Given two words (start and ...

  4. NGUI实现Sprite裁切成圆形或者椭圆形(不完美)

    先上效果 有个问题就是,UISprie用的Atlas的公用的材质,无法从当前要绘制的片段shader上获得uv百分比,所以当有其他的Sprite使用相同的Atlas时显示就有问题 其实Mesh是可以接 ...

  5. iOS UILocalNotification 每2周,每两个月提醒

    iOS 的UILocalNotification提醒提供了默认的重复频率,比如,一天,一个星期等等,但是对于非标准的频率,比如每,2周,每2个月,无法重复提醒. 我们的思路是在应用程序开始时,把即将发 ...

  6. 100m和1000m网线的常见制作方法

    100m和1000m网线的常见制作方法 100m和1000m网线的常见制作方法: 5类线(100m)的制作: a: 绿白(3).绿(6).橙白(1).蓝(4).蓝白(5).橙(2).棕白(7).棕(8 ...

  7. ASM:《X86汇编语言-从实模式到保护模式》第七章应用例:用adc命令计算1到1000的累加

    在16位的处理器上,做加法的指令是add,但是他每次只能做8位或者16位的加法,除此之外,还有一个带进位的加法指令adc(Add With Carry),他的指令格式和add一样,目的操作数可以是8位 ...

  8. 【leetcode】 Search a 2D Matrix (easy)

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  9. LeetCode 191 Number of 1 Bits

    Problem: Write a function that takes an unsigned integer and returns the number of '1' bits it has ( ...

  10. UVA 156 Ananagrams ---map

    题目链接 题意:输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文本中的另外一个单词.在判断是否满足条件时,字母不分大小写,但在输出时应保留输入中的大小写,按字典序进行排列( ...