748 - Exponentiation


Exponentiation

Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems.

This problem requires that you write a program to compute the exact value ofRn whereR is a real number (0.0 < R < 99.999) and n is an integer such that$0 < n \le 25$.

Input

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.

Output

The output will consist of one line for each line of input giving the exact value of R n. Leading zeros and insignificant trailing zeros should be suppressed in the output.

Sample Input

95.123 12
0.4321 20
5.1234 15
6.7592  9
98.999 10
1.0100 12

Sample Output

548815620517731830194541.899025343415715973535967221869852721
.00000005148554641076956121994511276767154838481760200726351203835429763013462401
43992025569.928573701266488041146654993318703707511666295476720493953024
29448126.764121021618164430206909037173276672
90429072743629540498.107596019456651774561044010001
1.126825030131969720661201


#include <stdio.h>
#include <string.h>
char s1[10000];
int a[50][100000],d[10000];
int main ()
{
    int i,j,n,m,s,t,k,y,x,z,u;
    int l,flag,b,c,weishu,flag1,position;
    while(scanf("%s %d",&s1,&m)!=EOF)
    {
        l=strlen(s1);
        flag=0;
        k=0;
        b=c=0;
        for(i=0;i<=l-1;i++)
        {
            if(s1[i]=='.')
            {
                k=1;
            }
            if(k==0)
            {
                b+=1;
            }
            if(k==1)
            {
                if(s1[i]>='1'&&s1[i]<='9')
                {
                    c+=1;
                }else if(s1[i]=='0')
                {
                    for(j=i+1;j<=l-1;j++)
                    {
                        if(s1[j]=='0')
                        {
                            ;
                        }else
                        {
                            break;
                        }
                    }
                    if(j!=l)
                    {
                        c+=1;
                    }
                }
            }
        }
        weishu=m*c;
        k=b+c;
        if(c!=0)
        {
            l=k+1;
        }else
        {
            l=k;
        }
        j=0;
        for(i=0;i<=l-1;i++)
        {
            if(s1[i]!='.')
            {
                d[j]=s1[i]-'0';
                a[0][flag]=s1[i]-'0';
                j+=1;
                flag+=1;
            }
        }
        n=j;
        for(i=0;i<=n-1;i++)
        {
            a[0][n-i-1]=d[i];
        }
        flag1=0;
        for(i=1;i<=m-1;i++)
        {
            flag1=0;
            u=0;
            position=0;
            for(j=n-1;j>=0;j--)
            {
                flag1=u;
                u+=1;
                for(y=0;y<=flag-1;y++)
                {
                    k=a[i-1][y]*d[j];
                    s=k/10;
                    x=k%10;
                    if(position<=flag1)
                    {

                        if(s==0)
                        {
                            a[i][position]=x;
                            position+=1;
                        }else
                        {
                            a[i][position]=x;
                            position+=1;
                            a[i][position]=s;
                            position+=1;
                        }
                    }else
                    {
                      if(s==0)
                      {
                          a[i][flag1]+=x;
                      }else
                      {
                          if(flag1<position-1)
                          {
                              a[i][flag1]+=x;
                              a[i][flag1+1]+=s;
                          }else
                          {
                              a[i][flag1]+=x;
                              a[i][position]=s;
                              position+=1;
                          }
                      }
                      for(z=flag1;z<=position-1;z++)
                      {
                          s=a[i][z]/10;
                          x=a[i][z]%10;
                          if(s==0)
                          {
                              ;
                          }else
                          {
                              if(z<=position-2)
                              {
                                 a[i][z+1]+=s;
                              }else
                              {
                                  a[i][position]=s;
                                  position+=1;
                              }
                              a[i][z]=x;
                          }
                      }
                    }
                    flag1+=1;
                }
            }
            flag=position;
        }
        if(weishu>=position)
        {
            printf(".");
            for(i=1;i<=weishu-position;i++)
            {
                printf("0");
            }
            for(i=position-1;i>=0;i--)
            {
                printf("%d",a[m-1][i]);
            }
        }else
        {
            for(i=position-1;i>weishu-1;i--)
            {
                if(a[m-1][i]!=0)
                {
                    break;
                }
            }
            if(i!=weishu-1)
            {
               for(i=position-1;i>weishu-1;i--)
               {
                   printf("%d",a[m-1][i]);
               }
            }
           printf(".");
           for(;i>=0;i--)
           {
               printf("%d",a[m-1][i]);
           }
        }
        printf("\n");
    }
    return 0;
}



Miguel A. Revilla
2000-02-09

 

#include <stdio.h>
#include <string.h>
char s1[10000];
int a[50][100000],d[10000];
int main ()
{
    int i,j,n,m,s,t,k,y,x,z,u;
    int l,flag,b,c,weishu,flag1,position;
    while(scanf("%s %d",&s1,&m)!=EOF)
    {
        l=strlen(s1);
        flag=0;
        k=0;
        b=c=0;
        for(i=0;i<=l-1;i++)
        {
            if(s1[i]=='.')
            {
                k=1;
            }
            if(k==0)
            {
                b+=1;
            }
            if(k==1)
            {
                if(s1[i]>='1'&&s1[i]<='9')
                {
                    c+=1;
                }else if(s1[i]=='0')
                {
                    for(j=i+1;j<=l-1;j++)
                    {
                        if(s1[j]=='0')
                        {
                            ;
                        }else
                        {
                            break;
                        }
                    }
                    if(j!=l)
                    {
                        c+=1;
                    }
                }
            }
        }
        weishu=m*c;
        k=b+c;
        if(c!=0)
        {
            l=k+1;
        }else
        {
            l=k;
        }
        j=0;
        for(i=0;i<=l-1;i++)
        {
            if(s1[i]!='.')
            {
                d[j]=s1[i]-'0';
                a[0][flag]=s1[i]-'0';
                j+=1;
                flag+=1;
            }
        }
        n=j;
        for(i=0;i<=n-1;i++)
        {
            a[0][n-i-1]=d[i];
        }
        flag1=0;
        for(i=1;i<=m-1;i++)
        {
            flag1=0;
            u=0;
            position=0;
            for(j=n-1;j>=0;j--)
            {
                flag1=u;
                u+=1;
                for(y=0;y<=flag-1;y++)
                {
                    k=a[i-1][y]*d[j];
                    s=k/10;
                    x=k%10;
                    if(position<=flag1)
                    {

                        if(s==0)
                        {
                            a[i][position]=x;
                            position+=1;
                        }else
                        {
                            a[i][position]=x;
                            position+=1;
                            a[i][position]=s;
                            position+=1;
                        }
                    }else
                    {
                      if(s==0)
                      {
                          a[i][flag1]+=x;
                      }else
                      {
                          if(flag1<position-1)
                          {
                              a[i][flag1]+=x;
                              a[i][flag1+1]+=s;
                          }else
                          {
                              a[i][flag1]+=x;
                              a[i][position]=s;
                              position+=1;
                          }
                      }
                      for(z=flag1;z<=position-1;z++)
                      {
                          s=a[i][z]/10;
                          x=a[i][z]%10;
                          if(s==0)
                          {
                              ;
                          }else
                          {
                              if(z<=position-2)
                              {
                                 a[i][z+1]+=s;
                              }else
                              {
                                  a[i][position]=s;
                                  position+=1;
                              }
                              a[i][z]=x;
                          }
                      }
                    }
                    flag1+=1;
                }
            }
            flag=position;
        }
        if(weishu>=position)
        {
            printf(".");
            for(i=1;i<=weishu-position;i++)
            {
                printf("0");
            }
            for(i=position-1;i>=0;i--)
            {
                printf("%d",a[m-1][i]);
            }
        }else
        {
            for(i=position-1;i>weishu-1;i--)
            {
                if(a[m-1][i]!=0)
                {
                    break;
                }
            }
            if(i!=weishu-1)
            {
               for(i=position-1;i>weishu-1;i--)
               {
                   printf("%d",a[m-1][i]);
               }
            }
           printf(".");
           for(;i>=0;i--)
           {
               printf("%d",a[m-1][i]);
           }
        }
        printf("\n");
    }
    return 0;
}


 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值