博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1002 487-3279
阅读量:5102 次
发布时间:2019-06-13

本文共 4851 字,大约阅读时间需要 16 分钟。

487-3279
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 295738   Accepted: 52972

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

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 这题很简单! 下面是把每行数据转换为整型,再排序处理,但是考虑到诸如001-1010,以0开头的号码串,后面输出的时候还要处理一下,不方便!本代码输出时未作处理,不可取!推荐下面第二种!
1 #include
2 #include
3 #include
4 #include
5 using namespace std; 6 int main() 7 { 8 //ifstream in("test.txt"); 9 int ysb[26];10 ysb[0]=ysb[1]=ysb[2]=2;11 ysb[3]=ysb[4]=ysb[5]=3;12 ysb[6]=ysb[7]=ysb[8]=4;13 ysb[9]=ysb[10]=ysb[11]=5;14 ysb[12]=ysb[13]=ysb[14]=6;15 ysb[15]=ysb[17]=ysb[18]=7;16 ysb[19]=ysb[20]=ysb[21]=8;17 ysb[22]=ysb[23]=ysb[24]=9;18 int n;19 int i,j;20 string s;21 cin>>n;22 int *arr=new int[n];23 memset(arr,0,sizeof(int)*n);24 for(i=0;i
>s;27 int k=1000000;28 for(j=0;j
='0'&&s[j]<='9')31 {32 arr[i]+=(s[j]-'0')*k;33 k/=10;34 }35 if(s[j]>='A'&&s[j]<='Y')36 {37 arr[i]+=(ysb[s[j]-65])*k;38 k/=10;39 }40 if(k==0)41 break;42 }43 }44 sort(arr,arr+n);45 int flag=0;46 int count=1;47 for(i=1;i
1)57 cout<
=n)64 {65 if(flag&&count>1)66 cout<

string字符串版:

1 #include
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 int main() 8 { 9 //ifstream in("test.txt");10 char ysb[26];11 ysb[0]=ysb[1]=ysb[2]='2';12 ysb[3]=ysb[4]=ysb[5]='3';13 ysb[6]=ysb[7]=ysb[8]='4';14 ysb[9]=ysb[10]=ysb[11]='5';15 16 ysb[12]=ysb[13]=ysb[14]='6';17 ysb[15]=ysb[17]=ysb[18]='7';18 ysb[19]=ysb[20]=ysb[21]='8';19 ysb[22]=ysb[23]=ysb[24]='9';20 int n;21 int i,j;22 string s;23 cin>>n;24 vector
arr;25 string str_temp="12345678";26 for(i=0;i
>s;29 int k=0;30 for(j=0;j
='0'&&s[j]<='9')34 str_temp[k++]=s[j]; 35 if(s[j]>='A'&&s[j]<='Y')36 str_temp[k++]=ysb[s[j]-65];37 if(k==3)38 str_temp[k++]='-';39 if(k>=8)40 {41 arr.push_back(str_temp);42 break;43 }44 } 45 }46 sort(arr.begin(),arr.end());47 int flag=0;48 int count=1;49 for(i=1;i
1)59 cout<
<<" "<
<
=n)66 {67 if(flag==1)68 {69 if(count>1)70 cout<
<<" "<
<
View Code

 

 

转载于:https://www.cnblogs.com/zhaopeng938/p/7546181.html

你可能感兴趣的文章
MyBaits动态sql语句
查看>>
HDU4405(期望DP)
查看>>
拉格朗日乘子法 那些年学过的高数
查看>>
vs code 的便捷使用
查看>>
Spring MVC @ResponseBody返回中文字符串乱码问题
查看>>
用户空间与内核空间,进程上下文与中断上下文[总结]
查看>>
JS 中的跨域请求
查看>>
JAVA开发环境搭建
查看>>
mysql基础语句
查看>>
Oracle中的rownum不能使用大于>的问题
查看>>
[Data Structure & Algorithm] 有向无环图的拓扑排序及关键路径
查看>>
cassandra vs mongo (1)存储引擎
查看>>
Visual Studio基于CMake配置opencv1.0.0、opencv2.2
查看>>
遍历Map对象
查看>>
MySQL索引背后的数据结构及算法原理
查看>>
#Leetcode# 209. Minimum Size Subarray Sum
查看>>
SDN第四次作业
查看>>
DM8168 DVRRDK软件框架研究
查看>>
django迁移数据库错误
查看>>
yii 跳转页面
查看>>