您的位置:首页 > 其它

POJ 1002 487-3279

2014-12-16 01:21 281 查看
TimeLimit:2000MSMemoryLimit:65536K
TotalSubmissions:248809Accepted:44216
Description

Businessesliketohavememorabletelephonenumbers.Onewaytomakeatelephonenumbermemorableistohaveitspellamemorablewordorphrase.Forexample,youcancalltheUniversityofWaterloobydialingthememorableTUT-GLOP.Sometimesonlypartofthenumberisusedtospellaword.WhenyougetbacktoyourhoteltonightyoucanorderapizzafromGino'sbydialing310-GINO.Anotherwaytomakeatelephonenumbermemorableistogroupthedigitsinamemorableway.YoucouldorderyourpizzafromPizzaHutbycallingtheir``threetens''number3-10-10-10.
Thestandardformofatelephonenumberissevendecimaldigitswithahyphenbetweenthethirdandfourthdigits(e.g.888-1200).Thekeypadofaphonesuppliesthemappingofletterstonumbers,asfollows:
A,B,andCmapto2
D,E,andFmapto3
G,H,andImapto4
J,K,andLmapto5
M,N,andOmapto6
P,R,andSmapto7
T,U,andVmapto8
W,X,andYmapto9
ThereisnomappingforQorZ.Hyphensarenotdialed,andcanbeaddedandremovedasnecessary.ThestandardformofTUT-GLOPis888-4567,thestandardformof310-GINOis310-4466,andthestandardformof3-10-10-10is310-1010.
Twotelephonenumbersareequivalentiftheyhavethesamestandardform.(Theydialthesamenumber.)
Yourcompanyiscompilingadirectoryoftelephonenumbersfromlocalbusinesses.Aspartofthequalitycontrolprocessyouwanttocheckthatnotwo(ormore)businessesinthedirectoryhavethesametelephonenumber.
Input

Theinputwillconsistofonecase.Thefirstlineoftheinputspecifiesthenumberoftelephonenumbersinthedirectory(upto100,000)asapositiveintegeraloneontheline.Theremaininglineslistthetelephonenumbersinthedirectory,witheachnumberaloneonaline.Eachtelephonenumberconsistsofastringcomposedofdecimaldigits,uppercaseletters(excludingQandZ)andhyphens.Exactlysevenofthecharactersinthestringwillbedigitsorletters.
Output

Generatealineofoutputforeachtelephonenumberthatappearsmorethanonceinanyform.Thelineshouldgivethetelephonenumberinstandardform,followedbyaspace,followedbythenumberoftimesthetelephonenumberappearsinthedirectory.Arrangetheoutputlinesbytelephonenumberinascendinglexicographicalorder.Iftherearenoduplicatesintheinputprinttheline:
Noduplicates.
SampleInput

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

SampleOutput

310-10102
487-32794
888-45673

大致意思是给出一个字符串,然后根据映射规则转换为标准字符串,最后统计一下重复的电话号码各有多少个,如果没有重复的就输出‘Noduplicates.’。
这道题目还是很简单的,没有什么特殊的技巧。这里我将电话号码转换成一个7位的整数这样节约存储一些,运算处理起来也比较方便。,然后最这些整数进行排序,最后输出。

下面是代码:


/***************************************************
*POJ1002487-3279
*author:樊列龙
*2014.12.16
***************************************************/

#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>

/**
*获取映射规则下的字符(数字)
*
*/
intgetMapNum(charch)
{
switch(ch)
{
case'A':case'B':case'C':
return2;
case'D':case'E':case'F':
return3;
case'G':case'H':case'I':
return4;
case'J':case'K':case'L':
return5;
case'M':case'N':case'O':
return6;
case'P':case'R':case'S':
return7;
case'T':case'U':case'V':
return8;
case'W':case'X':case'Y':
return9;
}
}

intcmp(constvoid*a,constvoid*b)
{
return*(int*)a-*(int*)b;
}

intmain()
{
intN,i,j;
scanf("%d\n",&N);
inta[200000];
for(i=0;i<N;i++)
{
chars[256];
scanf("%s",s);
intlen=strlen(s);

intj=0;
for(j=0;j<=len;j++)
{
charch=s[j];
if(isdigit(ch))
{
a[i]=a[i]*10+ch-'0';
}
elseif(isalpha(ch))
{
a[i]=a[i]*10+getMapNum(ch);
}
}
}

qsort(a,N,sizeof(int),cmp);

i=0,j=0;
intisDuplicates=1;
while(i<N-1)
{
j=i;
while(a[i]==a[i+1])
{
i++;
}

if(i!=j)
{
printf("%03d-%04d%d\n",a[i]/10000,a[i]%10000,i-j+1);
isDuplicates=0;
}
i++;
}

if(isDuplicates)
{
printf("Noduplicates.\n");
}
return0;
}







                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: