POJ1002 487-3279
来源:互联网 发布:我的世界自瞄辅助js 编辑:程序博客网 时间:2024/06/05 00:46
487-3279
Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 199680 Accepted: 34770
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.
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.
No duplicates.
Sample Input
124873279ITS-EASY888-45673-10-10-10888-GLOPTUT-GLOP967-11-11310-GINOF101010888-1200-4-8-7-3-2-7-9-487-3279
Sample Output
310-1010 2487-3279 4888-4567 3
Source
East Central North America 1999
模拟吧,不解释了,看代码吧。可能我做的有点麻烦,将就着吧。
#include<iostream>#include<cstdio>#include<cstring>#include<map>#include<algorithm>using namespace std;struct node{ int a,b;}q[100002];bool pai(node x,node y){ if(x.a==y.a)return x.b<y.b; else return x.a<y.a;}int main(){ map<char,int>p; p['1']=1; p['2']=2; p['3']=3; p['4']=4; p['5']=5; p['6']=6; p['7']=7; p['8']=8; p['9']=9; p['0']=0; p['A']=2; p['B']=2; p['C']=2; p['D']=3; p['E']=3; p['F']=3; p['G']=4; p['H']=4; p['I']=4; p['J']=5; p['K']=5; p['L']=5; p['M']=6; p['N']=6; p['O']=6; p['P']=7; p['R']=7; p['S']=7; p['T']=8; p['U']=8; p['V']=8; p['W']=9; p['X']=9; p['Y']=9; int t; char c[50]; scanf("%d",&t); for(int i=0;i<t;i++) { scanf("%s",&c); int l=strlen(c); q[i].a=0; q[i].b=0; int num=0; int j; for(j=0;j<l;j++) { if(c[j]!='-') { q[i].a=10*q[i].a+p[c[j]]; num++; if(num==3)break; } } for(j=j+1;j<l;j++) { if(c[j]!='-') { q[i].b=10*q[i].b+p[c[j]]; } } } sort(q,q+t,pai); int v=0; int s=0; for(int i=0;i<t;i++) { v++; if(q[i].a!=q[i+1].a||q[i].b!=q[i+1].b) { if(v!=1) { s=1; if(q[i].a==0)cout<<"000-"; else if(q[i].a<10)cout<<"00"<<q[i].a<<"-"; else if(q[i].a<100)cout<<"0"<<q[i].a<<"-"; else cout<<q[i].a<<"-"; if(q[i].b==0)cout<<"0000"<<" "; else if(q[i].b<10)cout<<"000"<<q[i].b<<" "; else if(q[i].b<100)cout<<"00"<<q[i].b<<" "; else if(q[i].b<1000)cout<<"0"<<q[i].b<<" "; else cout<<q[i].b<<" "; cout<<v<<endl; } v=0; } } if(s==0)cout<<"No duplicates."<<endl; return 0;}
- POJ1002·487-3279
- POJ1002 487-3279
- POJ1002 487-3279
- POJ1002--487-3279
- poj1002 487-3279
- poj1002 487-3279
- POJ1002 487-3279
- poj1002 487-3279
- poj1002 487-3279(哈希)
- POJ1002 487-3279
- POJ1002--487-3279 翻译
- [c]poj1002 487-3279
- 【poj1002】487-3279
- POJ1002 487-3279
- poj1002 487-3279
- POJ1002 487-3279
- POJ1002 487-3279
- POJ1002--487-3279
- Chrome , Firfox 对应IE fireEvent 的方法
- Hibernate读书笔记-----Hibernate的关联映射之N-N关联映射 .
- memcached简单的使用教程
- C++ 私有成员变量的理解
- 在从1到n的正数中1出现的次数[算法]
- POJ1002 487-3279
- memcached协议及命令
- 构造函数中抛出异常
- Windows环境下搭建Android
- MFC中实现画线的几种方法:
- memcached常见命令
- inifiles.ReadString 会丢失不可见字符
- grails 笔记
- osecvs 视频会议系统设计(二):VOIPGateway设计