| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 555 人关注过本帖
标题:POJ1001
只看楼主 加入收藏
黄河十三号
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2012-3-28
结帖率:80%
收藏
 问题点数:0 回复次数:1 
POJ1001
高精度求R的n次幂
Description

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 of Rn where R is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0 < n <= 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 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.
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

原题地址:http://

谁能给个代码参考参考啊,刚接触这种题,想不出来
搜索更多相关主题的帖子: computer experience involving national 
2012-03-28 20:18
绿茶盖儿
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:1
帖 子:363
专家分:1852
注 册:2011-9-3
收藏
得分:0 
程序代码:
#include<stdio.h>
#include<string.h>
#define maxsize 128
#define len 5
int main()
{
   char R[6];
   int n;
   while(scanf(" %s %d",R,&n)!=EOF)     
   {
      int i,j=0,k,p;
      int b[maxsize]={0},c[len]={0}; 
      for(i=strlen(R)-1;i>=0;i--)
      {
          if(R[i]=='.'){k=i;continue;} 
          else                          
          {
             b[j]=(int)(R[i]-'0');
             c[j]=(int)(R[i]-'0');
             j++;                       
          }
      }
      p=n*(strlen(R)-k-1);   
      for(i=1;i<n;i++)   
      {    
         int a[maxsize]={0};
         for(k=0;k<len;k++)    
         {
             for(j=0;j<maxsize;j++)
                a[k+j]+=b[j]*c[k];
         }
         for(k=0;k<maxsize;k++)
         {
             if(a[k]>=10)
             {
                 a[k+1]+=a[k]/10;
                  a[k]%=10;
             }
         }
         for(k=0;k<maxsize;k++)
            b[k]=a[k];
      } 
      for(i=maxsize-1;i>=p;i--)
          if(b[i]!=0) break;    
      for(j=i;j>=p;j--)
          printf("%d",b[j]);
      for(i=0;i<p;i++)
          if(b[i]!=0) break;
      if(i<p)
      {
          printf("%c",'.');
          for(j=p-1;j>=i;j--)
              printf("%d",b[j]);
      }
      printf("\n");
   }
   return 0;
}
2012-03-30 10:11
快速回复:POJ1001
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017487 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved