1002查表 排序 检测.docx
- 文档编号:6766805
- 上传时间:2023-01-10
- 格式:DOCX
- 页数:4
- 大小:16.02KB
1002查表 排序 检测.docx
《1002查表 排序 检测.docx》由会员分享,可在线阅读,更多相关《1002查表 排序 检测.docx(4页珍藏版)》请在冰豆网上搜索。
1002查表排序检测
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
Source
EastCentralNorthAmerica1999pku前面的题目都是关于输入输出的题目,虽然不难,但是想一次就AC也不是件容易的事情。
1002这道题目涉及输入、转换、排序、格式输出问题。
其中有些技巧:
1。
用scanf和printf进行输入输出,比iostream效率高很多,最少一个数量级。
2。
进行转换时用到了查表方法,很不错哦……
3。
排序不用多说,冒泡肯定不行,效率太低,用STL的sort。
4。
边算边输。
×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
sourcecode
#include
#include
usingnamespacestd;
intmain()
{
intarray[200000];//用于存储号码信息,记住一定要开大
charmap[]="22233344455566677778889999";//转换时查表用
memset(array,0,100001);//把array的元素都设为0
chartemp[100];//用于接收输入信息
longn,k=0;//n是接收n个号码的个数,k是一个下标
intcount=1;//用于计数相同的号码个数,用于判断和输出
boolopen=false;//判断是否各个号码都不相同
scanf("%d",&n);//接收个数信息
while(k { scanf("%s",temp); for(inti=0;temp[i];i++) { if(temp[i]<='9'&&temp[i]>='0') { array[k]=array[k]*10+temp[i]-'0'; } elseif(temp[i]<'Z'&&temp[i]>='A') array[k]=array[k]*10+map[temp[i]-'A']-'0'; } k++; } sort(array,array+n);//排序 for(k=0;k { if(array[k]==array[k+1]) { open=true; count++; } elseif(count! =1) { printf("%03d-%04d%d\n",array[k]/10000,array[k]%10000,count); count=1; } } if(count! =1) { printf("%03d-%04d%d\n",array[k]/10000,array[k]%10000,count); count=1; } if(open==false) printf("Noduplicates.\n");//无相同号码 return0; }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 1002查表 排序 检测 1002
![提示](https://static.bdocx.com/images/bang_tan.gif)