当前位置: 代码迷 >> C语言 >> 高精度求小数的幂次方 真的希望各位大哥能指点一下 谢谢
  详细解决方案

高精度求小数的幂次方 真的希望各位大哥能指点一下 谢谢

热度:404   发布时间:2007-10-17 10:02:34.0
高精度求小数的幂次方 真的希望各位大哥能指点一下 谢谢

Time Limit:1000MS Memory Limit:65536K
Total Submit:0 Accepted:0

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


Hint

If you don't know how to determine wheather encounted the end of input:
s is a string and n is an integer

Source

East Central North America 1988

搜索更多相关的解决方案: 小数  高精度  

----------------解决方案--------------------------------------------------------
各位大哥大姐 请指教
----------------解决方案--------------------------------------------------------

#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
char a[150]={0};
int n;
while(scanf("%s%d",a,&n)!=EOF)
{ int b[150]={0},i,j,lend,num1,num2,num,sum=0,ten=1,suger;
lend=strlen(a)-1;
for(i=0;i<=lend;i++)
if(a[i]=='.')
break;
num1=lend-i;
for(j=i;j<lend;j++)
a[j]=a[j+1];
lend=lend-1;
for(j=lend;j>=i;j--)
{ if(a[j]!='0')
break;
}
num2=lend-j;
lend=j;
num=(int)fabs(num1-num2);
num=num*n;
for(i=0;i<=lend;i++)
b[i]=a[i]-48;
do
{ sum=sum+b[lend]*ten;
ten=ten*10;
lend--;
} while(lend>=0);
int temp,la,digit[1000];
la = 0,digit[0] = 1;
for(temp=1;temp<=n;temp++)
{
digit[0] = digit[0]*sum;
for(i=1;i<=la;i++)
{
digit[i] = digit[i]*sum;
digit[i] = digit[i] + digit[i-1]/10;
digit[i-1] = digit[i-1]%10;
}
while(digit[la]>=10)
{
la= la + 1;
digit[la] = digit[la-1] /10;
digit[la-1] = digit[la-1]%10;
}
}
if(b[0]==0)
{ printf(".");
for(i=num;i>la+1;i--)
printf("0");
for(i=la;i>=0;i--)
printf("%d",digit[i]);
}
else if(num!=0)
{ for(i=la;i>=num;i--)
printf("%d",digit[i]);
printf(".");
for(i=num-1;i>=0;i--)
printf("%d",digit[i]);
}
else if(num==0)
for(i=la;i>=0;i--)
printf("%d",digit[i]);
printf("\n");
}
return 0;
}


----------------解决方案--------------------------------------------------------
楼上的程序还有问题.

Don't print the decimal point if the result is an integer.

还有输入
2 10

输出:

.0000000000
----------------解决方案--------------------------------------------------------
把小数化为整数来做.
----------------解决方案--------------------------------------------------------
我的对了 题目要求只能输入小数 如整数输入10.0 才行 我的是把小数化为整数来做啊
谢了 各位
----------------解决方案--------------------------------------------------------
对于整数
另外有程序
#include <iostream>
using namespace std;
int main()
{
int n,temp,la,i,digit[310],c;
while(cin>>c>>n)
{
la = 0,digit[0] = 1;
for(temp=1;temp<=n;temp++)
{
digit[0] = digit[0]*c;
for(i=1;i<=la;i++)
{
digit[i] = digit[i]*c;
digit[i] = digit[i] + digit[i-1]/10;
digit[i-1] = digit[i-1]%10;
}
while(digit[la]>=10)
{
la= la + 1;
digit[la] = digit[la-1] /10;
digit[la-1] = digit[la-1]%10;
}
}
for(i=la;i>=0;i--)
cout<<digit[i];
cout<<endl;
}
return 0;
}

----------------解决方案--------------------------------------------------------
楼主把你的代码发到http://yzfy.org/bbs/viewthread.php?tid=123试试看



by 雨中飞燕 C/C++学习讨论群:46520219
[url=http://yzfy.org/]C/C++算法习题(OnlineJudge)论坛:[/url] http://yzfy.org/
Blog: http://yzfy.programfan.com

[url=http://bbs.bc-cn.net/viewthread.php?tid=163571]请大家不要用TC来学习C语言,点击此处查看原因[/url] [url=http://blog.programfan.com/article.asp?id=24801]请不要写出非int声明的main函数[/url]
[url=http://bbs.bc-cn.net/viewthread.php?tid=162918]C++编写的Windows界面游戏[/url]
----------------解决方案--------------------------------------------------------

我的程序和你的题目不一样啊
听说您变成很厉害啊
指点一下我的提问啊
谢谢


----------------解决方案--------------------------------------------------------
我的题目是北大acm1001题
http://acm.pku.edu.cn/JudgeOnline/
----------------解决方案--------------------------------------------------------
  相关解决方案