POJ 1002 487-3279
2015-10-05 15:34
357 查看
标题来源:http://poj.org/problem?id=1002]
487-3279
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
Sample Output
Source
East Central North America 1999
题意: 依据给定的变换规则,将字符串转换成相应的"电话号码"~ 然后按字典序输出各个“电话号码”出现的次数。
题解: 这题可算是搞死我了! 開始时TLE到死,后来是WA到哭。
TLE的原因有两个:
1.我先统计各个"号码"出现的次数之后再进行排序,这样效率非常低~ 先排序再直接输出就能够了。
2.作死的cpp 字符串
WA是由于一个小bug...在别人博客上看到一组測试数据。试了一下,我的程序竟然没有输出。
这才算是把错误找出来了。加一条语句就AC了
AC代码:
487-3279
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 246666 | Accepted: 43755 |
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
题意: 依据给定的变换规则,将字符串转换成相应的"电话号码"~ 然后按字典序输出各个“电话号码”出现的次数。
题解: 这题可算是搞死我了! 開始时TLE到死,后来是WA到哭。
TLE的原因有两个:
1.我先统计各个"号码"出现的次数之后再进行排序,这样效率非常低~ 先排序再直接输出就能够了。
2.作死的cpp 字符串
WA是由于一个小bug...在别人博客上看到一组測试数据。试了一下,我的程序竟然没有输出。
这才算是把错误找出来了。加一条语句就AC了
AC代码:
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #define Max 200005 using namespace std; char num[]={'2','2','2','3','3','3','4','4','4','5','5','5','6','6','6','7','0','7','7','8','8','8','9','9','9','0'}; int n; char Map[100],temp[100]; struct Node{ char s[50]; }str[Max]; void init(){ for(int i=0;i<26;i++) Map[i+'A']=num[i]; return ; } int cmp(const void *s,const void *t) { return strcmp( (*(Node *)s).s , (*(Node *)t).s); } int main() { scanf("%d",&n); init(); for(int i=0;i<n;i++) { int pos=0; scanf("%s",temp); for(int k=0;k<strlen(temp);k++) { if(temp[k]=='-'||temp[k]=='Q'||temp[k]=='Z') continue; if(temp[k]>='0'&&temp[k]<='9') str[i].s[pos++]=temp[k]; else if(temp[k]<='Z'&&temp[k]>='A') str[i].s[pos++]=Map[temp[k]]; if(pos==3) str[i].s[pos++]='-'; } str[i].s[pos]='\0'; } qsort(str,n,sizeof(str[0]),cmp); int pos=0; bool flag=true; for(int i=1;i<n;i++){ if(!strcmp(str[i].s,str[i-1].s)){ pos++; flag=false; if(i==n-1) cout<<str[i-1].s<<" "<<pos+1<<endl; } else if(pos){ cout<<str[i-1].s<<" "<<pos+1<<endl; pos=0; } } if(flag) cout<<"No duplicates."<<endl; return 0; }
相关文章推荐
- 用两个栈实现一个队列 JAVA实现
- 浏览器存储
- Python中用format函数格式化字符串的用法
- 线程 种类
- Cocos2d-x游戏 技能冷去 时间进度
- Linux查看CPU和内存使用情况
- vim基本配置.vimrc
- 黑马程序员----Objective-C学习笔记之动态类型检测
- 地图Legend控件的使用
- Java并发编程(一)线程定义、状态和属性
- Java并发编程(一)线程定义、状态和属性
- BitmapImage 的继承关系
- hibernate总结-N+1问题
- bzoj1688: [Usaco2005 Open]Disease Manangement 疾病管理(状压dp)
- 【转载】浅谈游戏开发之2D手游工具
- HDU-5120-Intersection【几何-相交圆面积】
- 电脑故障,路由器及网络
- 《一个操作系统的实现》——pmtest1.asm详解
- 电脑故障,路由器及网络
- 电脑故障,路由器及网络