幂问题

输入:

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;
}
   


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值