PKU题解Word文档格式.docx
《PKU题解Word文档格式.docx》由会员分享,可在线阅读,更多相关《PKU题解Word文档格式.docx(25页珍藏版)》请在冰豆网上搜索。
![PKU题解Word文档格式.docx](https://file1.bdocx.com/fileroot1/2022-10/29/690a07e2-850d-489b-ab00-00c78c569806/690a07e2-850d-489b-ab00-00c78c5698061.gif)
【题解】
A+b
【参考程序】
Programgh;
Vara,b:
longint;
Begin
Readln(a,b);
Writeln(a+b);
End.
求高精度幂
对数值很大、精度很高的数进行高精度计算是一类十分常见的问题。
比如,对国债进行计算就是属于这类问题。
现在要你解决的问题是:
对一个实数R(0.0<
R<
99.999),要求写程序精确计算R的n次方(Rn),其中n是整数并且0<
n<
=25。
T输入包括多组R和n。
R的值占第1到第6列,n的值占第8和第9列。
对于每组输入,要求输出一行,该行包含精确的R的n次方。
输出需要去掉前导的0后不要的0。
如果输出是整数,不要输出小数点。
95.12312
0.432120
5.123415
6.75929
98.99910
1.010012
548815*********830194541.899025343415715973535967221869852721
.00000005148554641076956121994511276767154838481760200726351203835429763013462401
43992025569.928573701266488041146654993318703707511666295476720493953024
29448126.764121021618164430206909037173276672
90429072743629540498.107596019456651774561044010001
1.126825*********720661201
Source
EastCentralNorthAmerica1988
Translator
北京大学程序设计实习,XieDi
【分析】
简单的高精度乘法
programgdjk;
typearr=array[1..10000]oflongint;
vari,j,n,lc,la,k:
a,c:
arr;
s:
string;
functionmul(a,b:
la,lb:
longint):
vari,j,x:
c:
begin
fillchar(c,sizeof(c),0);
fori:
=1tolado
begin
x:
=0;
forj:
=1tolbdo
c[i+j-1]:
=a[i]*b[j]+x+c[i+j-1];
=c[i+j-1]div10;
=c[i+j-1]mod10;
end;
{FOR_j}
c[i+j]:
=x;
{FOR_i}
lc:
=la+lb;
while(c[lc]=0)and(lc>
1)dodec(lc);
mul:
=c;
end;
{mul}
begin{main}
whilenoteofdo
readln(s);
val(copy(s,pos('
'
s)+1,length(s)-pos('
s)),n);
=copy(s,1,pos('
s)-1);
whiles[length(s)]='
0'
dodelete(s,length(s),1);
la:
=length(s);
=1tolength(s)do
ifs[i]<
>
'
.'
then
dec(la);
a[la]:
=ord(s[i])-ord('
);
end{IF}
elsek:
=i;
k:
=length(s)-k;
=k*n;
=a;
=length(s)-1;
=la;
=1ton-1do
=mul(a,c,la,lc);
ifk>
lcthen
write('
=k-1downtolcdo
{IF}
=lcdownto1do
ifi=kthenwrite('
c[i])
elsewrite(c[i]);
writeln;
{WHILE}
end.
P1002487-3279
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.
Theinputwillconsistofonecase.Thefirstlineoftheinputspecifiesthenumberoftelephonenumbersinthedirectory(upto100,000)asapositiveintegeraloneontheline.Theremaininglineslistthetelephonenumbersinthedirectory,witheachnumberaloneonaline.Eachtelephonenumberconsistsofastringcomposedofdecimaldigits,uppercaseletters(excludingQandZ)andhyphens.Exactlysevenofthecharactersinthestringwillbedigitsorletters.
Generatealineofoutputforeachtelephonenumberthatappearsmorethanonceinanyform.Thelineshouldgivethetelephonenumberinstandardform,followedbyaspace,followedbythenumberoftimesthetelephonenumberappearsinthedirectory.Arrangetheoutputlinesbytelephonenumberinascendinglexicographicalorder.Iftherearenoduplicatesintheinputprinttheline:
Noduplicates.
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
310-10102
487-32794
888-45673
EastCentralNorthAmerica1999
Des