输入:
The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6, and the n value will be in columns 8 and 9.
输出:
The output will consist of one line for each line of input giving the exact value of R^n. Leading zeros should be suppressed in the output. Insignificant trailing zeros must not be printed. Don't print the decimal point if the result is an integer.
ex
95.123 12
548815620517731830194541.899025343415715973535967221869852721
code:
#include<iostream>
#include <string>
int main()
{
char d[150]={0};
int n;
while(scanf("%s%d",d,&n)!=EOF)
{
int a[150]={0},b[150]={0},c[150]={0},temp,flag;
int lend,lena,lenb,lenc,len,i,j,k,digit,s;
lend=strlen(d)-1;
for(i=0;d[i];i++)if(d[i]=='.')break;
digit=lend-i;
for(j=i;d[j];j++)d[j]=d[j+1];
lend=lend-1;
for(i=0;i<=lend/2;i++)
{temp=d[i];d[i]=d[lend-i];d[lend-i]=temp;}
for(i=0;d[i];i++)a[i]=d[i]-48;
lena=lend;
for(i=0;i<=lena;i++)b[i]=a[i];
lenb=lena;
for(i=1;i<=n-1;i++)
{
for(j=0;j<=lenb;j++)
for(k=0;k<=lena;k++)
{
c[j+k]+=a[k]*b[j];
c[k+j+1]+=c[j+k]/10;
c[j+k]%=10;
}
k--;j--;
if(c[k+j+1]!=0)lenc=j+k+1;
else lenc=j+k;
for(j=0;j<=lenc;j++) b[j]=c[j];
lenb=lenc;
memset(c,0,sizeof(c));
}
digit=n*digit;
len=lenb+1-digit;
flag=0;
for(i=lenb-len;i>=0;i--)if(b[i]!=0){flag=1;break;}
if(flag==0)
{
for(i=lenb;i>=lenb-len+1;i--)printf("%d",b[i]);
printf("\n");
continue;
}
if(len==1&&b[lenb]==0)printf(".");
else
{
for(i=lenb;i>=lenb-len+1;i--)printf("%d",b[i]);
printf(".");
}
for(i=0;i<=lenb-len;i++)if(b[i]!=0){temp=i;break;}
for(i=lenb-len;i>=temp;i--)printf("%d",b[i]);
printf("\n");
}
return 0;
}