本题的测试用例十分刁钻,必须要考虑到很多的细节问题,在这里给出一组测试用例及运行结果:
95.123 12
548815620517731830194541.899025343415715973535967221869852721
0.4321 20
.00000005148554641076956121994511276767154838481760200726351203835429763013462401
5.1234 15
43992025569.928573701266488041146654993318703707511666295476720493953024
6.7592 9
29448126.764121021618164430206909037173276672
98.999 10
90429072743629540498.107596019456651774561044010001
1.0100 12
1.126825030131969720661201
.00001 1
.00001
.12345 1
.12345
0001.1 1
1.1
1.1000 1
1.1
10.000 1
10
000.10 1
.1
000010 1
10
000.10 1
.1
0000.1 1
.1
00.111 1
.111
0.0001 1
.0001
0.0001 3
.000000000001
0.0010 1
.001
0.0010 3
.000000001
0.0100 1
.01
0.0100 3
.000001
0.1000 1
.1
0.1000 3
.001
1.0000 1
1
1.0000 3
1
1.0001 1
1.0001
1.0001 3
1.000300030001
1.0010 1
1.001
1.0010 3
1.003003001
1.0100 1
1.01
1.0100 3
1.030301
1.1000 1
1.1
1.1000 3
1.331
10.000 1
10
10.000 3
1000
10.001 1
10.001
10.001 3
1000.300030001
10.010 1
10.01
10.010 3
1003.003001
10.100 1
10.1
10.100 3
1030.301
99.000 1
99
99.000 3
970299
99.001 1
99.001
99.001 3
970328.403297001
99.010 1
99.01
99.010 3
970593.059701
99.100 1
99.1
99.100 3
973242.271
99.998 1
99.998
0.0010 1
.001
下面是AC代码:
#include<stdio.h>
#include<string.h>
int c[];
int a[];
int b[];
int lenb,lenxiao,len;
void cal() {//计算部分
int i,j,k; memset(c,,sizeof(c));
if(lenxiao==){
len=;
}
else{
len=;
}
for(i=,k=;i<len;i++){
for(j=;j<lenb;j++){
c[i+j+]+=a[i]*b[j];
}
} for(i=len+lenb-;i>;i--){
if(c[i]>=){
c[i-]+=c[i]/;
c[i]=c[i]%;
}
}
if(c[]==){
for(i=;i<=len+lenb-;i++){
b[i-]=c[i];
}
lenb=len+lenb-;
}
else{
for(i=;i<=len+lenb-;i++){
b[i]=c[i];
}
lenb=len+lenb;
}
} void shuchu(int b[],int lenb){// 输出部分
int i,j;
for(i=;i<lenb-lenxiao;i++){
if(b[i]!=)
{
break;
}
}
if(i==lenb){
printf("0\n");
return;
}
for(j=lenb-;j>=lenb-lenxiao;j--){
if(b[j]!=){
break;
}
}
if(j==i&&b[i]==){
printf("0\n");
return ;
}
for(;i<=j;i++){
if(i==lenb-lenxiao){
printf(".");
}
printf("%d",b[i]);
}
printf("\n");
}
int main(int argc,char ** argv){
int power;
int i,j,k;
char input[];
while(scanf("%s",input)!=EOF){
scanf("%d",&power);
memset(a,,sizeof(a));
memset(b,,sizeof(b));
lenxiao=;
lenb=;len=;
for(i=,j=,lenb=;i<=;i++){ if(input[i]=='.'){
lenxiao = -i;
continue;
}
a[j++]=b[j]=input[i]-;
lenb++;
}
lenxiao*=power;
for(i=;i<power-;i++){
cal();
}
shuchu(b,lenb); }
return ;
}